Subarray With Target Sum

Medium · rating 1400 · Sliding Window, Two Pointers, Prefix Sum

The first line contains n and target t. The second line has n positive integers. Print YES if some contiguous subarray sums to exactly t, otherwise NO.

Constraints: 1 ≤ n ≤ 105, 1 ≤ ai, t ≤ 109

Related problems

Open Subarray With Target Sum in Code Arena →