Jumping on the Clouds c++ hackerrank solution code example
Example: hackerrank jumping on the clouds
def jumpingOnClouds(c):
len_c = len(c)
counter = 0
result = 0
print('c[]:', c)
while counter < len_c:
if counter + 2 < len_c:
print("current:", c[counter], "Two ahead:", c[counter+2], "counter:", counter,"result: ", result)
else:
print("current:", c[counter], "counter:", counter,"result: ", result)
if counter + 2 < len_c and c[counter+2] == 0:
counter = counter + 2
result = result + 1
continue
elif counter + 1 < len_c and c[counter+1] == 0:
counter = counter + 1
result = result + 1
continue
elif counter + 1 < len_c and c[counter+1] == 1:
counter = counter + 2
result = result + 1
continue
counter = counter + 1
print("result: ", result)
return result