5 kyu

Longest sequence with zero sum

483 of 783romanzes

Description:

Write a method that takes an array of signed integers, and returns the longest contiguous subsequence of this array that has a total sum of elements of exactly 0.

If more than one equally long subsequences have a zero sum, return the one starting at the highest index.

For example:
maxZeroSequenceLength([25, -35, 12, 6, 92, -115, 17, 2, 2, 2, -7, 2, -9, 16, 2, -11]) should return
[92, -115, 17, 2, 2, 2], because this is the longest zero-sum sequence in the array.

Arrays
Algorithms

More By Author:

Check out these other kata created by romanzes

Stats:

CreatedDec 20, 2013
PublishedDec 20, 2013
Warriors Trained1542
Total Skips104
Total Code Submissions6016
Total Times Completed783
JavaScript Completions483
CoffeeScript Completions43
Python Completions271
Total Stars50
% of votes with a positive feedback rating88% of 164
Total "Very Satisfied" Votes132
Total "Somewhat Satisfied" Votes24
Total "Not Satisfied" Votes4
Ad
Contributors
  • romanzes Avatar
  • lechevalier Avatar
  • JohanWiltink Avatar
  • albertogcmr Avatar
  • farhanaditya Avatar
Ad