FunctionRacerProblemsRace

Stepping Stones

BeginnerGreedyPython, JavaScript, TypeScript, Java, C++

stones lists the positions of stepping stones across a stream in strictly increasing order. You start on the first stone. From any stone you may hop to any later stone that is at most hop units farther along (a hop of exactly hop units is allowed). Return True if you can reach the last stone, otherwise False. With a single stone the answer is True.

Example 1

stones [0,3,5,9]
hop 4
returns true

The gaps are 3, 2 and 4, none larger than 4, so hopping stone to stone reaches the end.

Example 2

stones [0,3,8,9]
hop 4
returns false

The gap from 3 to 8 is 5, more than 4, and no stone lies in between, so you are stuck.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems