Gamified challenge · Greedy
Lily pads sit in a row. pads[i] (0 or more) is the longest jump the frog can make from pad i: from there it can land on any pad i + 1 to i + pads[i]. The frog starts on pad 0.
Write canReach(pads) (Python can_reach) that returns true if the frog can land on the last pad, and false otherwise. There is always at least one pad, and with a single pad the frog is already there.
Example: [2, 3, 1, 1, 4] is true (0 → 1 → 4), but [3, 2, 1, 0, 4] is false: every route ends on pad 3, whose jump is 0.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google