You are given a 0-indexed array of integers nums of length n. You start at nums[0]. Each element nums[i] represents the maximum jump length from that position. Return the minimum number of jumps to reach nums[n-1]. The test cases guarantee you can always reach the last index.
nums = [2,3,1,1,4]2nums = [2,3,0,1,4]2jumps=0, curEnd=0, farthest=0i = 0 .. n-2: update farthest = max(farthest, i + nums[i])i == curEnd: jumps++, advance curEnd = farthestjumps — the minimum number of jumps to reach last indexThink of each jump as a BFS level. Level 0 = just index 0. Level 1 = all platforms reachable in 1 jump. Level 2 = all reachable in 2 jumps, and so on. Instead of tracking exact paths, we scan the current level to find the farthest reachable index. When we exhaust the current level (i == curEnd), we commit exactly one jump and the new level spans curEnd+1 to farthest. This greedy frontier expansion always yields the minimum jumps in O(n).