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.
Input: skips = [1,3,2,1,4] Output: true
Jump 1 slide to slide 1, then 3 slides to the last one.
Input: skips = [2,1,0,0,3] Output: false
Every path lands on slide 2 or 3, and neither can move.
1 <= skips.length <= 1000000 <= skips[i] <= 100000Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #591 Hop to the Final Slide. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.