Notice Period

Fewest Bounces

medium

Same trampoline floor as before: from trampoline i you can bounce forward up to bounce[i] positions. This time the last trampoline is guaranteed reachable — the question is efficiency.

Return the minimum number of bounces needed to get from the first trampoline to the last. If you start on the last one, that's 0 bounces.

Example 1
in bounce = [2, 3, 1, 1, 4]
out 2
0 → 1 → 4: two bounces. No single bounce covers it.
Example 2
in bounce = [1, 1, 1, 1]
out 3
Each bounce advances one trampoline.
Constraints
  • · 1 <= len(bounce) <= 10^4
  • · 0 <= bounce[i] <= 1000
  • · the last index is always reachable
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.