Skip to content

Instantly share code, notes, and snippets.

@jeffcarp

jeffcarp/gist:6959725

Last active Dec 25, 2015
Embed
What would you like to do?
Max Consecutive Sum (problem of the week on http://codingforinterviews.com)
(defun max_consecutive_sum (arr)
(let ((max_ending_here 0) (max_so_far 0))
(dotimes (x (length arr))
(setf max_ending_here (max 0 (+ (aref arr x) max_ending_here)))
(setf max_so_far (max max_so_far max_ending_here)))
max_so_far))
(format t "~S~%" (max_consecutive_sum #(-1 5 6 -2 20 -50 4))) ; 29
(format t "~S~%" (max_consecutive_sum #(-2 1 -3 4 -1 2 1 -5 4))) ; 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.