Given an array
arr
of
n
integer elements, write a program to find the
length of the longest subarray with sum equals to 0.
Problem Note
- There can be multiple longest subarray with sum equals to 0. We have to just return the length.
- If no subarray has a sum equal to 0, then return 0.
Example 1
Input: arr[] = [15, -2, 0, -8, 3, 7, 10, 23]
Output: 5
Explanation: The largest subarray with 0 sum is [-2, 0, -8, 3, 7]
Example 2
Input: arr[] = [1, 2, 3]
Output: 0
Explanation: There is no subarray with 0 sum.