Jump Game
Welcome to the Jump Game challenge! Imagine a game where you are trying to jump across a series of stones. Each stone has a number on it, representing how far you can jump from that stone. Your task is to determine if you can reach the last stone, starting from the first stone.
You are given a list of non-negative integers where each index in the list represents a stone, and the value at each index represents the maximum number of stones you can jump forward from that stone. Let's say you have a list [2, 3, 1, 1, 4]. Starting from the first stone (first element in the list with value 2), you can jump to the second stone (index 1 with value 3) or the third stone (index 2 with value 1).
Your goal is to find out if you can reach the last stone (in this case, index 4) by making jumps according to the list values.
Examples
can_jump([2, 3, 1, 1, 4]) # returns True can_jump([3, 2, 1, 0, 4]) # returns False
In the first example, you can reach the last stone by jumping from the first stone to the second, and then making a jump directly to the last stone.
In the second example, you can't reach the last stone because eventually you hit a stone where you can't move forward (index 3 has value 0).
Have fun jumping and good luck!
Inputs
Arg 1:
[2,3,1,1,4]Expected Output
trueActual Output