Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a template on how to fill out a PR properly.
Description
To do so, we will create just 2 variables:
len
will store the length of our input;steps
is the array we mentioned above.We will initialised all cells of
steps
toINT_MAX
, but the first one, set to0
(since we start there and it takes no movement to reach it).Then we go for the main loop, going with
i
from0
up to the last element of our input and we will:len - 1
(last element of the array) andi + nums[i]
) (last element you can reach with the current jump) up to i (excluded);step[j]
is greater than what we can achieve jumping from the currently considered cell (step[i] + 1
) and in case updatestep[j]
to a smaller, more convenient value;step[j]
and all the cells left on the left ofj
, we break out of the inner loop and move on with another value ofi
.Once we are done, we can just return the last value of
steps
Related Issue
Acceptance Criteria
Type of Changes
Testing Steps / QA Criteria