Find a Subarray with Given Sum
Mediumjavapythonccppjavascript
Given an array of non-negative integers and a target sum, determine whether some contiguous subarray adds up to exactly that sum.
Input Format
The first line contains two integers N and target. The second line contains N space-separated non-negative integers.
Output Format
Print 1 if such a subarray exists, otherwise print 0.
Example 1
Input
6 33 1 4 20 3 10 5
Output
1
Explanation: The subarray [20, 3, 10] sums to 33.
- 1 <= N <= 100000
- 0 <= A[i] <= 1000000000
- 0 <= target <= 100000000000000