Created
December 21, 2015 17:50
-
-
Save rishiip/15b7f8ffd409e2383934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_array_max(one_dim_array) | |
one_dim_array.inject([0, 0]) do |(max_so_far, max_up_to_here), x| | |
new_max_up_to_here = [max_up_to_here + x, 0].max | |
new_max_so_far = [max_so_far, new_max_up_to_here].max | |
[new_max_so_far, new_max_up_to_here] | |
end.first | |
end | |
sample = [-2, 1, -3, 4, -1, 2, 1, -5, 4] | |
p get_array_max(sample) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wait.. may i ask what was the program supposed to return here?