Jump Game I
Try to solve the Jump Game problem.
We'll cover the following
Statement
In a single-player jump game, the player starts at one end of a series of squares, with the goal of reaching the last square.
At each turn, the player can take up to steps towards the last square, where is the value of the current square.
For example, if the value of the current square is , the player can take either steps, or steps, or step in the direction of the last square. The player cannot move in the opposite direction, that is, away from the last square.
You have been tasked with writing a function to validate whether a player can win a given game or not.
You’ve been provided with the nums
integer array, representing the series of squares. The player starts at the first index and, following the rules of the game, tries to reach the last index.
If the player can reach the last index, your function returns TRUE; otherwise, it returns FALSE.
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.
export function jumpGame(nums){// Replace this placeholder return statement with your codereturn false}