← Back
00:00

Frog Distance

SmithRx interview questions · Medium · Coding round · 7 tests

A row of N blocks is described by the integer array blocks, where each value is a block height. The blocks are indexed 0 through N - 1.

Both frogs begin on one shared block of your choosing. From there, one frog heads left and the other heads right, and the aim is to end up with as much space between them as possible. When the frogs finish on indices J and K with J <= K, their distance is counted as K - J + 1.

A hop is legal only onto a neighboring block that is at least as tall as the frog's current block. The left-moving frog only travels leftward and the right-moving frog only travels rightward; either of them is also allowed to remain where it is.

Idle