Frog Game ๐ธ
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[]) โ 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.