Skip to main content

Practice · 5 of 5

Subarray With Sum

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** Given a sorted (non-decreasing) array of n positive integers and a target s, print YES if some **contiguous** subarray sums to exactly s, else NO. **Input:** Line 1: n s (1 <= n <= 10^5, 1 <= s <= 10^14). Line 2: n sorted positive integers (1 <= a_i <= 10^9). **Output:** YES or NO. **Example:** 5 9 / 1 2 3 4 9 -> YES (2+3+4).

Back to lesson: Practice: Search Set