Imagine you're standing at the bottom of a tall ladder, ready to climb to the top! ๐ช The ladder has rungs at specific heights, but some gaps between rungs might be too large for you to safely climb.
You are given a strictly increasing integer array rungs that represents the height of existing rungs on the ladder. Starting from the floor at height 0, your goal is to reach the last (highest) rung.
However, there's a catch! You can only climb to the next rung if the distance between your current position and the next rung is at most dist. If the gap is too large, you'll need to add additional rungs at any positive integer heights to make the climb possible.
Your mission: Find the minimum number of rungs that must be added to make the entire ladder climbable!
Input & Output
Visualization
Time & Space Complexity
For each of n rungs, we might add up to max_gap/dist intermediate rungs
Only using constant extra space for counters
Constraints
- 1 โค rungs.length โค 105
- 1 โค rungs[i] โค 109
- 1 โค dist โค 109
- rungs is strictly increasing