FastPrepFrog Game ๐Ÿธ

Frog Game ๐Ÿธ

Microsoft logoMicrosoftโ— MediumOA
Learn

Problem statement

Given an array blocks where each value is the height of a block, two frogs start on the same block. A frog may jump to an adjacent block only when the destination is at least as high as its current block.

The frogs may start together on any block. Return the maximum number of blocks in the inclusive span between their final positions.

Function

maxDistanceBetweenFrogs(blocks: int[]) โ†’ int

Examples

Example 1

blocks = [9,2,5,3,0]return = 3

Start both frogs at the block with height 2. One frog jumps left to height 9, and the other jumps right to height 5. Their final positions span 3 blocks.

Example 2

blocks = [1,2,3,4,5,8]return = 6

Start both frogs at the first block. One frog stays there while the other moves right through every nondecreasing height. Their final positions span all 6 blocks.

More Microsoft problems

See Microsoft hiring insights
public int maxDistanceBetweenFrogs(int[] blocks) {
  // write your code here
}
blocks[9,2,5,3,0]
expected3
Checking accountโ€ฆ