We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
# jumpingOnClouds function below in python.defjumpingOnClouds(c,k):energy=100# got to next cloud by k stepsi=0+kwhileenergy>0:'''Theternaryoperatorsaretocheckifitsathundercloud(c[i]==1):thenwedecrementenergyby3(sourcetodestination)elseifitsaclumbus(c[i]==0):thenwedecrementenergyby1'''# prevent array out of indexifi>=len(c):i-=len(c)ifi==0:# reached cloud zero, game stopsenergy=energy-1ifc[i]==0elseenergy-3breakelse:energy=energy-1ifc[i]==0elseenergy-3i+=kreturnenergy
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Jumping on the Clouds: Revisited
You are viewing a single comment's thread. Return to all comments →