Trains the technique from
LeetCode 45Jump Game IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A courier drone sits on the first of a row of rooftop landing pads, indexed from 0 to len(reach) - 1.
You are given an integer array reach. When the drone lifts off from pad i, its remaining battery lets it settle on any pad from i + 1 up to and including i + reach[i], whichever of those pads exist. A single takeoff-and-landing counts as one flight. A pad whose value is 0 has no charging coil, so a drone that lands there can never lift off again.
Return the fewest flights that carry the drone from pad 0 to the last pad. The route planner only ever hands you a row in which the last pad is attainable, and a drone that already starts on the last pad needs no flights at all.
Example 1
One flight of three pads lands on pad 3, then a flight of a single pad finishes the trip. No single flight spans four pads from the start.
Example 2
Hop to pad 1, whose charge of 4 covers the two dead pads and lands directly on pad 5.
Example 3
The only pad in the row is also the destination.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def fewest_flights(reach: list[int]) -> int:public int fewestFlights(int[] reach)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.