Skip to content

Instantly share code, notes, and snippets.

@Sadamingh
Created September 6, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sadamingh/c984f8af62a5175505b40f3c869e0136 to your computer and use it in GitHub Desktop.
Save Sadamingh/c984f8af62a5175505b40f3c869e0136 to your computer and use it in GitHub Desktop.
def constrained_sum(nums: List[int]) -> int:
current, previous = 0, 0
for value in nums:
previous, current = current, max(current, previous + value)
return current
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment