Write a function that returns the maximum sum of a contiguous subsequence of integers in a vector.
(max-sum ) ;=> 0 ; (sum of empty seq is 0) (max-sum ) ;=> 1 (max-sum [1 10]) ;=> 11 (max-sum [-1]) ;=> 0 (because you can choose the empty subsequence, which has sum 0) (max-sum [3 -6 2 4 -2 7 -9]) ;=> 11 (sum of [2 4 -2 7])
They say you can do it in linear time and constant space. Just make sure it works with large vectors.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/