Back to course home
0% completed
Vote For New Content
Jump Game II (medium)
Problem Statement
You are given an array nums
containing n
integers, where nums[i]
represents the maximum length of a forward jump you can make from index i
. You are initially positioned at nums[0]
.
Return the minimum number of jumps needed to reach from the start
to the end
of the array.
Examples
Example 1:
- Input: nums =
[2, 3, 2, 2, 1]
- Expected Output: 2
- Justification: Start at index 0 and jump to index 1 (jump size 1). Then, jump from index 1 to the end (jump size 3).
Example 2:
- Input: nums =
[1, 2, 3, 4, 5]
- Expected Output: 3
- Justification: Start at index 0, jump to index 1 (jump size 1). Then, jump to index 3 (jump size 2). Finally, jump to the end (jump size 2).
Example 3:
- Input: nums =
[2, 3, 1, 2, 4, 1]
- Expected Output: 3
- Justification: Start at index 0, jump to index 1 (jump size 1). Then, jump to index 4 (jump size 2). Finally, jump to the end (jump size 1).
Constraints:
- 1 <= nums.length <= 10<sup>4</sup>
- 0 <= nums[i] <= 1000
- It's guaranteed that you can reach nums[n - 1].
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible