Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Frog Jump

XPChallenge Points: 30
levelLevel: Hard

A frog wants to reach the opposite side of a river and can step only on stones placed at certain distances.
The frog starts on the first stone and its initial jump must be exactly 1 unit.
If the previous jump was k units, the next jump may be k - 1, k, or k + 1 units.
The frog can move only forward, and it cannot land in water.
Determine whether the frog can reach the last stone.

Example 1:

Input: stones = [0,1,2,4,7,11,16]

Output: true

Explanation:

Possible jumps: 1 → 1 → 2 → 3 → 4 → 5.

Example 2:

Input: stones = [0,1,3,6,10,15,18]

Output: false

Explanation:

The jump difference becomes impossible to maintain to reach the final stone.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result