Skip to the code
cf.
+10 XP

#591 Hop to the Final Slide

easy

A presentation app has a "skip ahead" feature: on slide i, the presenter may jump forward by any number of slides from 1 up to skips[i]. A slide with skips[i] = 0 lets them go nowhere.

Write canReachLast(skips) that returns true if the presenter can get from the first slide to the last slide, and false otherwise. A deck with one slide is already at the end.

Example 1

Input: skips = [1,3,2,1,4]
Output: true

Jump 1 slide to slide 1, then 3 slides to the last one.

Example 2

Input: skips = [2,1,0,0,3]
Output: false

Every path lands on slide 2 or 3, and neither can move.

Constraints

  • 1 <= skips.length <= 100000
  • 0 <= skips[i] <= 100000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).