Problem ยท Array
Frog Game ๐ธ
Learn this problemProblem 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.
๐ข Source note (Jul 17, 2026): The first example counted the span differently from the second. Distance now means the number of blocks in the inclusive span, which makes both examples consistent. The judged core task matches the source intent at about 98%.
Function
maxDistanceBetweenFrogs(blocks: int[]) โ intExamples
Example 1
blocks = [9,2,5,3,0]return = 3Start 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 = 6Start 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.