← DiffPush

Jump Game

Standard Bar Greedy Approach · Medium O(n) · O(1)

The Courier Relay Reachability

A courier network spans relay posts in a line; each post advertises how many hops forward it can dispatch. A parcel starts at the first post and must reach the final one. The dispatcher tracks the farthest post reachable so far — if the scan ever lands beyond that frontier, the chain is broken and delivery fails.

Input: An integer array nums where nums[i] is the maximum hop length from post i.

Output: Return true if the last post is reachable from the first, false otherwise.

Constraints

Examples

Example 1

Input: {"nums":[2,3,1,1,4]}
Output: true
Hop to post 1, then its 3-hop range covers the final post.

Example 2

Input: {"nums":[3,2,1,0,4]}
Output: false
The zero post strands the parcel — every route dead-ends before index 4.

Solve this in your browser →

Also on LeetCode ↗