Problem
There is a city named Hackerland having number of buildings .We are given the height array of the buildings in the city. We are stuck at one end of the city and we need to go to the other end. We start from the first building and want to reach the last building.
We can jump to any of the next buildings in front of us from our current building with a constraint such that we cannot make a jump of height difference larger than the jump before it except the first building where we can make a jump of any height difference.
What are the minimum jumps required to reach the last building of the city ?
Input Format :
Output Format:
Print the minimum jumps to reach the last builiding or in case we cannot reach print .
Constraints:
Here , the minimum steps required to reach the last building is 3. We can do jumps following the order 1->3->5->6.
Also note that if we jump from 1st building to 2nd building ,we cannot make a jump to 3rd building now but can jump to 4th building as height difference of 1 and 2 is abs(1-3)=2 which is less than height difference of 2 and 3 is abs(5-1)=4 whereas height difference of 2 and 4 is abs(1-1)=0 .