Using the same "skip ahead" feature, from slide i the presenter may jump forward by 1 up to skips[i] slides.
Write fewestHops(skips) that returns the fewest jumps needed to get from the first slide to the last slide, or -1 if the last slide can't be reached. A deck with one slide needs 0 jumps.
Input: skips = [1,3,2,1,4] Output: 2
Jump to slide 1, then to the last slide.
Input: skips = [2,1,0,0,3] Output: -1
Slides 2 and 3 are dead ends that every path runs into.
1 <= skips.length <= 1000000 <= skips[i] <= 1000Run 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).
I'm here to help with #592 Fewest Hops 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.