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.
Input: stones = [0,1,2,4,7,11,16]
Output: true
Explanation:
Possible jumps: 1 → 1 → 2 → 3 → 4 → 5.
Input: stones = [0,1,3,6,10,15,18]
Output: false
Explanation:
The jump difference becomes impossible to maintain to reach the final stone.
Accepted:
Submission: