Skip to content

Instantly share code, notes, and snippets.

@aaronshaver
Created April 11, 2022 21:42
Show Gist options
  • Save aaronshaver/18e55f92fa3e1e04f2966082adf78c30 to your computer and use it in GitHub Desktop.
Save aaronshaver/18e55f92fa3e1e04f2966082adf78c30 to your computer and use it in GitHub Desktop.
IterTools accumulate
# this is the classic "return highest altitude" of hill climbing problem
from itertools import accumulate
def largestAltitude(self, A):
return max(0, max(accumulate(A)))
# the reason for the "0, " is because of data sets like [-4,-3,-2,-1,4,3,2]
# where the accumulated addition of those values is -1, yet starting altitude is 0,
# which is higher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment