This question evaluates a candidate's ability to implement a discrete simulation and perform array manipulation while correctly handling deterministic scan rules, tie-breaking, and boundary conditions.
You are given an integer array heights representing a 1D terrain (each index is a column height), an integer V (units of water), and an index K where water is poured.
Water is poured one unit at a time onto column K. For each unit:
K
, move left while the next column is
not higher
than the current. Among all reachable positions on the left with the
minimum height
, the water settles at the
leftmost
such position.
heights[K]
was found by the left scan), it then tries to flow
right
symmetrically: move right while the next column is
not higher
than the current. Among all reachable positions on the right with the
minimum height
, the water settles at the
rightmost
such position.
K
.
After placing all V units, return the resulting heights array.
heights
: array of non-negative integers
V
: non-negative integer (units of water)
K
: integer index (
0 <= K < len(heights)
)
heights
array after all water is poured.
1
.