How to solve the problem in O(n)
Anonymous User
114

Write an algorithm that, given an array of integers, determines whether there is a subarray (of size at-least-one) with a sum of 0

Examples:

Input: [4, 2, -3, 1, 6]
Output: true
There is a subarray with zero sum from index 1 to 3.

Input: [4, 2, 0, 1, 6]
Output: true
There is a subarray with zero sum from index 2 to 2.

Input: [-3, 2, 3, 1, 6]
Output: false
There is no subarray with zero sum.

Comments (2)