Skip to content

Instantly share code, notes, and snippets.

@codecakes
Created October 4, 2021 21:59
Show Gist options
  • Save codecakes/2d6b46c912047de9e392ab2fe0b3a1ae to your computer and use it in GitHub Desktop.
Save codecakes/2d6b46c912047de9e392ab2fe0b3a1ae to your computer and use it in GitHub Desktop.
jumping on clouds
"""
https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem
"""
def jumpingOnClouds(c, idx = 0, cache = None):
n = len(c)
jumps = 0
for idx in iter(lambda: idx, -1):
if c[idx] == 0:
if idx + 2 < n and c[idx+2] == 0:
jumps += 1
idx += 2
elif idx + 1 < n and c[idx+1] == 0:
jumps += 1
idx += 1
else:
return jumps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment