Created
September 25, 2023 01:54
-
-
Save themichaelyang/ccf590ce5f84bf544f4ca99fb20fd32f 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 max_score(card_points, k) | |
left_sums = cumulative_sum(card_points[0...k]).prepend(0) | |
right_sums = cumulative_sum(card_points[-k..-1].reverse_each).reverse.append(0) | |
left_sums.zip(right_sums).map(&:sum).max | |
end | |
def cumulative_sum(iter) | |
sum = 0 | |
iter.map {|x| sum += x} | |
end |
Author
themichaelyang
commented
Sep 25, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment