3
false; // If flag is true no more operations in recursion, directly return statement5
public boolean canCross(int[] stones) {6
int i = 0; // starting stone7
int k = 1; // starting jump9
return canBeCrossed(stones, k, i);12
public boolean canBeCrossed(int[] stones, int k, int i) {13
if (!flag) { // If flag is false17
- 1]) { // If frog do 'k' jump from current stone lands on last stones, no more18
// recusive calls and return true22
// If frog do 'k' jump from current stone crosses last stone or not able to reach next stone24
if ((stones[i] + k > stones[stones.length - 1]) || (stones[i] + k < stones[i + 1]))26
int temp = i + 1; // identify which next stone frog can reach27
// Find untill which stone frog can jump28
// So jump from current stone not greater than next possible stone exit loop29
while (stones[i] + k > stones[temp]) temp++;30
// If loop exited 2 condition possible31
// jump from current stone is reached next possible stone34
// If next possible stone reached35
// then do all possible jumps from this stone36
// the current stone is 'temp'37
// possible jumps are 'k-1', k, 'k+1'38
if (stones[i] + k == stones[temp])39
return (canBeCrossed(stones, k + 1, temp)40
|| canBeCrossed(stones, k, temp)41
|| canBeCrossed(stones, k - 1, temp));43
// If next possible stone not reached means jump from the current stone can't reach any stone