Jump Game II Problem

Jump Game II Problem — ExecCode Easy DSA Practice

Solve the Jump Game II problem on ExecCode. Free online easy DSA practice in Greedy. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a 0-indexed array of integers nums of length n. Your task is to compute the required answer and return the minimum number of jumps to reach index n - 1. You are initially positioned at index 0. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at index i, you can jump to any index (i + j) where: - 0 <= j <= nums[i] and.

Examples

Input {"nums": [2, 3, 1, 1, 4]}; Output 2. Input {"nums": [2, 3, 0, 1, 4]}; Output 2. Input {"nums": [0]}; Output 0

Constraints

1 <= nums.length <= 10^4 0 <= nums[i] <= 1000 It's guaranteed that you can reach nums[n - 1].

Practice Jump Game II free on ExecCode. Browse DSA problems, topic map, and placement guides.