Zero Sum Subarray
Mediumjavapythonccppjavascript
Determine whether the array contains a non-empty contiguous subarray whose elements sum to zero.
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print 1 if a zero-sum subarray exists, otherwise print 0.
Example 1
Input
5 4 2 -3 1 6
Output
1
Explanation: The subarray [2, -3, 1] sums to 0.
- 1 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Longest Subarray with Sum KMedium · java, python, c, cpp, javascriptSolve Problem
- Longest Consecutive SequenceMedium · java, python, c, cpp, javascriptSolve Problem
- Group AnagramsMedium · java, python, c, cpp, javascriptSolve Problem