Zero Sum

Input is denoted by an array N.

  • Your task is to find the length of the longest contiguous subarray such that its sum is 0.
  • A contiguous subarray is a sequence of elements in an array that are adjacent to each other, e.g. in [1,2,3,4,5] one possible contiguous subarray is [1,2,3] or [2,3,4]

Example Case

Input: N = [2, -2, 3, -3, 4]
Output: 4
Explanation : [2, -2, 3, -3] sums to 0


Case 1

Input: N = [7, 3, -4, 2, -6, 5, 1, -3, 9, -2, 4, -8, 6, -1, 2, -7, 8, -3, 5, -5, 11, -4, 3, 2, -6, 7, -9, 4, 1, -3, 6, -2, 8, -6, 5, -1, 7, -4, 2, -8, 9, -3, 4, -5, 6, 2, -7, 3, -1, 5, -2, 8, -6, 4, -3, 7, -5, 2, 1, -4, 6, -2, 9, -7, 3, -1, 4, -6, 8, -5, 2, 7, -3, 1, -4, 6, -2, 5, -7, 9, 3, -8, 6, 4, -5, 7, -3, 2, -6, 8, -1, 5, -4, 9, -7, 3, -2, 6, -8, 4, 2, -5, 7, -3, 1, -6, 8, -4, 5, -2, 9, -7, 3, -1, 6, -5, 2, -8, 4, 7, -3, 5, -6, 8, -2, 1, -4, 9, -7, 3, -5, 6, -1, 2, -8, 7, -4, 5, -3, 6, 2, -7, 8, -5, 4, -1, 3, -6, 9, -2]


Case 2

The file is too big! Access the input here!

Submit Here