FastPrepFastPrep
Problem Brief

Frog Game ๐Ÿธ

OA
See Microsoft online assessment and hiring insights

Given an array blocks where each cell represents the height of the current block, two frogs start on the same block. Each frog can only jump to another adjacent block if it is higher or equal to the one it is on. Return the maximum distance that can be between the two frogs if they can start together on any block.

1Example 1

Input
blocks = [9,2,5,3,0]
Output
2
Explanation
Let the two frogs start on cell 4 and one of them go to cell 2. (There is another option here that will give you 2).

2Example 2

Input
blocks = [1,2,3,4,5,8]
Output
6
Explanation
If both frogs start at cell 5.
public int maxDistanceBetweenFrogs(int[] blocks) {
  // write your code here
}
Input

blocks

[9,2,5,3,0]

Output

2

Sign in to submit your solution.