End of Array Reachable

Languages

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.

Input

  • numbers: number[]: An array of integers, each index's value is the maximum number of positions reachable from that index

Examples

Input: numbers = [4,1,0,0,2,3]
Output: true
Explanation: Move from index 0 to 4, then move 1 position to the last index.
Input: numbers = [1,0,0,0]
Output: false
Explanation: 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: true
Explanation: 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.

Constraints

  • 1 <= numbers.length <= 10,000
  • 0 <= numbers[i] <= 100,000
The TypeScript Denial Tee — TypeScript love, "any" denialSponsor: SwagOverflow
The TypeScript Denial Tee — TypeScript love, "any" denial

You swear by TypeScript, but we all know what's lurking in your code. This black tee perfectly captures the silent shame of every front end dev who totally loves strict typing — until any saves the day. Clean, witty, and painfully relatable, it's the ultimate uniform for TypeScript warriors in denial.

Get yours now ->

The TypeScript Denial Tee — TypeScript love, "any" denialSponsor: SwagOverflow
The TypeScript Denial Tee — TypeScript love, "any" denial

You swear by TypeScript, but we all know what's lurking in your code. This black tee perfectly captures the silent shame of every front end dev who totally loves strict typing — until any saves the day. Clean, witty, and painfully relatable, it's the ultimate uniform for TypeScript warriors in denial.

Get yours now ->

As traduções do pt-BR estão em beta e podem não ser precisas. Dê feedback ou entre em contato conosco se estiver interessado em ajudar a traduzir!