Skip to content

Minimum number of jumps to reach end #84

@aflexar

Description

@aflexar

Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function to return the minimum number of jumps to reach the end of the array (starting from the first element). If an element is 0, they cannot move through that element. If the end isn’t reachable, return -1.

Examples:

Input: arr[] = {1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9}
Output: 3 (1-> 3 -> 8 -> 9)
Explanation: Jump from 1st element
to 2nd element as there is only 1 step,
now there are three options 5, 8 or 9.
If 8 or 9 is chosen then the end node 9
can be reached. So 3 jumps are made.

Metadata

Metadata

Assignees

Labels

ccode in c languageduplicateThis issue or pull request already existsenhancementNew feature or requestgood first issueGood for newcomershacktoberfestthis repo is eligible for hacktoberfest 2021hacktoberfest-acceptedThis tag ensures that your PRs here will be countedhelp wantedExtra attention is neededjavacode in java languagepythoncode in python languagequestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions