Created
October 4, 2021 21:59
-
-
Save codecakes/2d6b46c912047de9e392ab2fe0b3a1ae to your computer and use it in GitHub Desktop.
jumping on clouds
This file contains hidden or 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
""" | |
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