Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Find the maximum distance from all value
- 2. set k= the maximum value
- 2. If you can complete the process as sample on Problem, then print initial k, Otherwise print initial k+1 .
- Let, the height of the rungs from the ground are 2, 8, 11, 16, 21 respectively
- maximum distance is 6, k=6
- Jumped 2 foot from the ground to the 1st rung (ground to 1). Since I jumped less than k feet, k remains 6.
- Jumped 6 feet for the next rung (2 to 8). Since I jumped equal k feet, k becomes 5.
- Jumped 3 foot for the 3rd rung (8 to 11). So, k remains 5.
- Jumped 5 feet for the 4th rung (11 to 16). This k becomes 4.
- Jumped 5 feet for the 5th rung (16 to 21). This time i need to jump 5 but k is 4, you canβt complete the process.
- So, the Ans = 6+1=7
- Thanks :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement