The Pour Water problem simulates dropping k units of water onto a terrain at a given index. Each water unit flows left first (to a lower point), then right (if it can't go left), and stays at the drop point if it can't flow anywhere lower. This coding problem simulates each water unit's movement. The array and simulation interview pattern is the core.
Airbnb and Oracle ask this simulation problem because it tests careful directional movement simulation with priority rules: try left before right. Each water unit follows a greedy downhill path.
Per-unit simulation with directional priority. For each water unit: start at index. Try to flow left: move left while heights[pos-1] < heights[pos]. If pos == 0 or heights[pos-1] >= heights[pos], check if pos moved left from index. If yes, place water here (heights[pos]++). Else, try flowing right similarly. If neither works, place at index.
heights=[2,1,1,2,1,2,1,3,1,1,2,2], k=4, index=5.
Simulation problems require careful directional logic. Pour Water's rules: (1) try to find the leftmost position you can flow to, (2) if that position is lower than current, go there; (3) otherwise try right; (4) if neither, stay. Implement with two separate loops for left and right. Practice similar "gravity simulation" problems: "water levels in containers," "trapping rain water." Simulation correctness depends on precise rule encoding.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Average Waiting Time | Medium | Solve | |
| Count Unhappy Friends | Medium | Solve | |
| Find The First Player to win K Games in a Row | Medium | Solve | |
| Find the Winner of an Array Game | Medium | Solve | |
| Maximum Profit of Operating a Centennial Wheel | Medium | Solve |