i holds lengths[i], the longest forward jump allowed from it. From cell i you may land on any cell from i + 1 to i + lengths[i] as long as you stay inside the row.
You start on cell 0. Find the smallest number of jumps needed to land on the last cell. The last cell is guaranteed to be reachable.lengths=[3, 1, 1, 4, 0, 2, 1] → 2
Jump from cell 0 to cell 3, then straight to the last cell, 6. Two jumps.
lengths=[1, 1, 1, 1] → 3
Every jump moves exactly one cell, three in total.
lengths=[5] → 0
There is only one cell, so no jumps are needed.
len(lengths) ≤ 10⁵lengths[i] ≤ 10⁵0lengths=[3, 1, 1, 4, 0, 2, 1]
2
Run checks the first 3 tests in your browser. Submit checks all 39 tests on the server, hidden ones included.