Given an array of integers numbers
where each element in the array represents the maximum number of positions that can be moved forward from that index; it is acceptable to move by fewer positions.
Determine whether it is possible to reach the last index of the array by starting from the first index. Return true
if it can be reached and false
otherwise.
numbers: number[]
: An array of integers, each index's value is the maximum number of positions reachable from that indexInput: numbers = [4,1,0,0,2,3]Output: trueExplanation: Move from index 0 to 4, then move 1 position to the last index.
Input: numbers = [1,0,0,0]Output: falseExplanation: Can only move from index 0 to index 1 and no further movements thereafter, so it impossible to reach the last index.
Input: numbers = [2,3,1,1,4]Output: trueExplanation: Move 1 position forward from index 0 to index 1 (it is allowed to move up to 2 positions, but going to index 1 first allows us to move further). From index 1, move 3 positions to reach the last index.
numbers.length
<= 10,000numbers[i]
<= 100,000Every dev's worst enemy? Their own code from a month ago. This black tee captures that moment of existential crisis when you debug your own work and wonder who could have written this mess, only to realize it was you. A must-have for front end engineers who know the struggle.
Every dev's worst enemy? Their own code from a month ago. This black tee captures that moment of existential crisis when you debug your own work and wonder who could have written this mess, only to realize it was you. A must-have for front end engineers who know the struggle.
Given an array of integers numbers
where each element in the array represents the maximum number of positions that can be moved forward from that index; it is acceptable to move by fewer positions.
Determine whether it is possible to reach the last index of the array by starting from the first index. Return true
if it can be reached and false
otherwise.
numbers: number[]
: An array of integers, each index's value is the maximum number of positions reachable from that indexInput: numbers = [4,1,0,0,2,3]Output: trueExplanation: Move from index 0 to 4, then move 1 position to the last index.
Input: numbers = [1,0,0,0]Output: falseExplanation: Can only move from index 0 to index 1 and no further movements thereafter, so it impossible to reach the last index.
Input: numbers = [2,3,1,1,4]Output: trueExplanation: Move 1 position forward from index 0 to index 1 (it is allowed to move up to 2 positions, but going to index 1 first allows us to move further). From index 1, move 3 positions to reach the last index.
numbers.length
<= 10,000numbers[i]
<= 100,000Every dev's worst enemy? Their own code from a month ago. This black tee captures that moment of existential crisis when you debug your own work and wonder who could have written this mess, only to realize it was you. A must-have for front end engineers who know the struggle.
console.log()
statements will appear here.