Jumping on the Clouds

Problem statement:-

Solution:-Simple but not so straight forward hackerrank problem where we have to count the number of jumps based on which type of cloud is allowed to jump on it or not in that case the jump range will increase.

Photo by Jason Blackeye on Unsplash

Let move towards the code,we declare two variables “i” and jump” and give them an initial value of 0.We will iterate the cloud list using a while loop which iterate till (length of cloud list-1) as we need to iterate each and every cloud type in cloud list.We will compare the i+1 and i+2 cloud in the list for current iteration and based on that we will jump by 2 jumps or 1 jump.

along with that in if loop we will always check if the cloud list has not been exhausted i.e i+2<n or i+1<n. We will increment the number of jumps and value of i in each iteration based on jump count.

“Try and Fail but don’t Fail to Try”.
An excellent quote for this problem as I have been struggling to optimize my solution for this problem. Keep learning and Keep hustling…(cheers:-PN)

Work in progress