Pour water onto a terrain

0
Remix

An array gives the height of each column of a terrain.

  1. Print the terrain.
  2. Drop a given number of water units at a column, one at a time. Each unit moves left if it can eventually fall lower that way, else right, else it stays where it is and raises the level there. Print the terrain with the water.

Make the movement rules exact before coding, and keep the printing code separate from the simulation.

AirbnbTechnical phone screenLast asked Feb 2026
No answer yet. Write the first one; the best answer gets endorsed.