DIY: Frog Jump
Solve the interview question "Frog Jump in this lesson.
We'll cover the following
Problem statement
A river is divided into units. At each unit, there may or may not be a stone. A frog has to cross the river. It can jump on a stone, but it must not jump into the water.
You are given a list of the positions of the stones
in a sorted and ascending order. You have to determine if the frog can cross the river by landing on the last stone. The frog starts at the first stone. Let’s assume that the first jump is 1
unit. If the frog’s last jump was k
units, its next jump must either be k - 1
, k
, or k + 1
units. The frog can only jump forward.
You will be given an array of integers called stones
, which will contain the positions of the stones. You will return true
if the frog can cross the river using the last stone. Otherwise, you will return false
.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.