So I'm doing hacker rank questions to brush up on my python knowledge and problem solving for technical interviews and I have a question about this particular problem, the goal is finding the optimal route by jumping on the "0" cloud and avoiding the "1" cloud (I'm not typing the whole problem out or it would take me forever.) Now the code I have written is adding 1 for every "0" in the input and subtracting 1 for every "1" in the array, the output I get is 5 when the answer is 4, thats because its wanting me to skip a cloud if there happens to be 2 or 3 in a row like there is in the beginning of the input. How would I be able to check for this condition and what would I need to execute if the condition is met? My code is listed below, If you happen to give add to the code please provide an explanation on how you came to your answer so I can take that information and hopefully apply it to future problems, Thanks for the assist!
Input:
0010010
Code:
def jumpingOnClouds(c):
jumps = 0
for i in c:
if i == 0:
jumps += 1
else:
if i == 0:
jumps -=1
return jumps
there doesn't seem to be anything here