Jump Game II

Intermediate Greedy Techniques DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Jump Game 2, Dynamic Programming, Greedy Algorithm, space complexity, dynamic programming, greedy algorithm, bfs, array traversal, time complexity analysis, Graph Traversal (BFS), Fractional Knapsack.

Problem Statement Given an array of non negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. For example, if you are at index i and nums[i] is x, you can jump to any index i + j where: 1 <= j <= nums[i] i + j < nums.length Your goal is to reach the last index in the minimum number of jumps . You can assume that you can always reach the last index. Input Specification A single line containing a list of integers (the array nums). Output Specification A single integer representing the minimum number of jumps required to reach the last index. Constraints 1 ≤ nums.length ≤ 10^4 0 ≤ nums[i] ≤ 1000 It is guaranteed that you can reach the last index. Sample Test Cases Sample Input 1 Sample Output 1 Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index. Sample Input 2 Sample Output 2 Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index. Note that you cannot jump to index 2 because nums[2] is 0, which would make you get stuck. Sample Input 3 Sample Output 3 Explanation: You are already at the last index (which is also the first index). No jumps are needed. Difficulty Level Medium