frog jump

Sun, 03 May 2026 19:14:24 +0000

The frog can jump on a stone, but it must not jump into the water. Given a list of stones positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. From any stair i, the frog has two options: it can either jump to the (i+1)th stair or the (i+2)th stair. The cost of a jump is the absolute difference in height between the two stairs. You have a frog that needs to cross a river by jumping on stones. The river is divided into units, and stones are placed at certain unit positions. The frog starts on the first stone and must reach the last. The frog starts at the first stone (position 0) and its first jump must be 1 unit. If the frogs last jump was k units, then its next jump should be either k - 1, k, or k + 1 units.