Jump Game I
Try to solve the Jump Game problem.
Statement
Given an array of integers called nums
, each element represents a square in a game board. At each turn, the player can take up to steps toward the last square, where is the value of the current square. This means from any position, you can move forward by any number of steps from up to the value at that position. Starting at the first index, your goal is to determine whether it’s possible to reach the last index of the array. Write a function that returns TRUE if you can reach the end, or FALSE if you get stuck somewhere.
Constraints:
-
nums.length
-
nums[i]
Examples
Understand the problem
Let’s take a moment to make sure you've correctly understood the problem. The quiz below helps you check if you're solving the correct problem:
Jump Game I
Can you reach the end of [1, 2, 3, 4, 5] if you start from the very first element?
Yes
No
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground.
function jumpGame(nums){// Replace this placeholder return statement with your codereturn false}export {jumpGame};