Given an array A 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 just return 0.

Example 1

Input: A[] = [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: A[] = [1, 2, 3]
Output: 0
Explanation: There is no subarray with 0 sum.