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.
intjumpingOnClouds(vector<int>c,intk){intenergy=100;boolstarted=false;autohandleJump=[&energy,&started,&k](vector<int>c,int&index)->bool{// costs of jumpenergy--;// if thunderhead if(c[index]==1)energy-=2;// calculate index of next cloudindex+=k;if(index>=c.size())index=index%c.size();if(!started)started=true;// if reached start cloudif(started&&index==0){returnfalse;}returntrue;};intindex=0;while(handleJump(c,index)){}returnenergy;}
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 →
C++ Solution: