The problem. Given an array arr of integers (positive, negative or zero), return the length of the longest subarray — a run of consecutive elements — whose sum is 0. If there is none, return 0.
arr = [15, -2, 2, -8, 1, 7, 10, 23] -> 5 ([-2, 2, -8, 1, 7])
arr = [1, 2, -3, 3, -1, -2] -> 6 (the whole array)
arr = [1, 2, 3] -> 0 (no subarray adds up to 0)Free account
Sign up to read the rest of this lesson: 7 more sections, 4 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come