Dsa
Dynamic Programming
Easy
Jump Game II
You are given an array of non-negative integers where each element represents the maximum jump length at that position. Your task is to find the minimum number of jumps needed to reach the last index of the array, starting from the first index. You can jump to the any index within your jump range.
Input:
- The first line contains an integer n (1 ≤ n ≤ 1000), the length of the array.
- The second line contains n space-separated non-negative integers, representing the jump lengths.
Output:
- A single integer representing the minimum number of jumps needed to reach the end of the array.
Example:
Input:
6
2 3 1 1 4 0
Output:
2
Explanation:
Jump from index 0 to index 1 (or 2), then jump to the last index (4).
Key concepts
dynamic_programminggreedyarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now