Monday, December 9, 2013

[Amazon] Subarray with sum 0

Given an array of integers with positive and negative numbers. Find if there exist a subarray with sum 0. If any, print the starting index, otherwise print 0.

Example:  Input Array: {1,2, 3, -1, 4, -3, 2}
               Subarray is: {-1, 4, -3} which gives sum as 0.


No comments:

Post a Comment