You are given a 1D terrain represented by an integer array heights, where heights[i] is the height of the column at index i.
Write a function to print an ASCII visualization of the terrain where:
+
characters.
Example input:
heights = [5,4,3,2,1,3,4,0,3,4]
Example rendering (one possible formatting):
+
++ + +
+++ ++ ++
++++ ++ ++
+++++++ ++
++++++++++ <--- base layer
Implement dumpWater(heights, waterAmount, column) that simulates pouring waterAmount units of water onto the terrain at index column.
For each unit of water:
i = column
.
eff(left) <= eff(current)
.
eff < eff(column)
, settle at the leftmost position among the lowest reached.
column
.
After all water is poured, print the final ASCII visualization using:
+
for terrain blocks
W
for water blocks (stacked above the terrain)
Example call:
dumpWater([5,4,3,2,1,3,4,0,3,4], waterAmount=8, column=1)
Expected output should match the described final state (formatting may vary as long as block positions are correct).
renderTerrain(heights) -> void
dumpWater(heights, waterAmount, column) -> void
(may return the final water distribution and/or print the final rendering)
1 <= len(heights) <= 10^4
0 <= heights[i] <= 10^5
0 <= column < len(heights)
0 <= waterAmount <= 10^5
Your solution should be correct and reasonably efficient for the above constraints.