Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
JUMP GAME
MEDIUM
40 mins
Dynamic Programming
Greedy
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Dynamic Programming
-
-
Greedy
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

JUMP GAME

Medium
yellow-spark
0/80
Avg time to solve 40 mins
Success Rate 35 %
Share
0 upvotes

Problem Statement

Given an array of non-negative integers ‘ARR’ of length ‘N’, you are initially positioned at the array's first index.

Each element in the array represents your maximum jump length at that position.

Return the minimum number of jumps required to reach the last index.

If it is not possible to reach the last index, return -1.

Example:
Input:

‘N’ = 3
‘ARR’ = [ 2, 1, 1 ]

The shortest way to reach index 2 is
Index 0 => Index 2
that requires only 1 jump.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
5
2 3 1 1 4
4
1 1 1 1

Sample Output 1:

2
3
Explanation Of Sample Input 1:
For the first test case:-
The optimal path is:
0 => 1 => 4

For the second test case:-
0 => 1 => 2 => 3
Sample Input 2:
2
5
2 3 0 1 4
3
1 0 2    
Sample Output 2:
2
-1
Reset Code
Full screen
Auto
copy-code
Console