755. Pour Water
mediumAsked at AirbnbSimulate dropping V units of water at index K on a height array. Each unit prefers left, then right, then stays. Airbnb asks this to test careful simulation — the rules are pickier than they look.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Airbnb loops.
- Glassdoor (2026-Q1)— Airbnb L4/L5 onsite reports include Pour Water as a signature Airbnb simulation problem.
- Blind (2025-11)— Frequently mentioned as the 'classic Airbnb' onsite problem.
Problem
You are given an elevation map represented as an integer array heights where heights[i] represents the height of the terrain at index i. The width at each index is 1. You are also given two integers volume and k where volume units of water will fall at index k. Water first drops at index k and rests on top of the highest terrain or water at that index. Then, it flows according to the rules: if the droplet would eventually fall by moving left, then move left; otherwise, if the droplet would eventually fall by moving right, then move right; otherwise, rise at its current position. Return an array representing the final heights after all volume units have been poured.
Constraints
1 <= heights.length <= 1000 <= heights[i] <= 990 <= volume <= 20000 <= k < heights.length
Examples
Example 1
heights = [2,1,1,2,1,2,2], volume = 4, k = 3[2,2,2,3,2,2,2]Example 2
heights = [1,2,3,4], volume = 2, k = 2[2,3,3,4]Example 3
heights = [3,1,3], volume = 5, k = 1[4,4,4]Explanation: After 4 units fill the valley, 5th rises at k.
Approaches
1. Per-drop simulation (optimal for this problem size)
For each of the volume units, scan left from k for the lowest spot, then right, then deposit at the best.
- Time
- O(volume * n)
- Space
- O(1)
function pourWater(heights, volume, k) {
for (let v = 0; v < volume; v++) {
let best = k;
// try left
for (let i = k - 1; i >= 0; i--) {
if (heights[i] > heights[best]) break;
if (heights[i] < heights[best]) best = i;
}
if (best !== k) { heights[best]++; continue; }
// try right
for (let i = k + 1; i < heights.length; i++) {
if (heights[i] > heights[best]) break;
if (heights[i] < heights[best]) best = i;
}
heights[best]++;
}
return heights;
}Tradeoff: Direct simulation matches the problem statement line-by-line. For volume=2000 and n=100 this is 200k operations — fast enough. Clean answer for the constraint.
2. Same idea, slightly faster with break conditions
Identical to above but stop the inner loop early when a strictly higher terrain blocks further flow.
- Time
- O(volume * n) worst case
- Space
- O(1)
function pourWaterOpt(heights, volume, k) {
function direction(start, step) {
let best = start;
let i = start + step;
while (i >= 0 && i < heights.length) {
if (heights[i] > heights[best]) break;
if (heights[i] < heights[best]) best = i;
i += step;
}
return best;
}
for (let v = 0; v < volume; v++) {
const left = direction(k, -1);
if (left !== k) { heights[left]++; continue; }
const right = direction(k, 1);
heights[right]++;
}
return heights;
}Tradeoff: Refactor with a helper — same big-O but cleaner code. Both approaches handle the rules identically; pick whichever you write bug-free.
Airbnb-specific tips
Airbnb's bar on this is reading the rules carefully. Say out loud: 'Try left first — find the lowest spot reachable without going UP. If left improves over k, deposit there. Otherwise try right. If neither, rise at k.' Many candidates skip the 'without going up' constraint and get wrong answers on inputs like [3,1,3].
Common mistakes
- Letting the droplet 'climb' over a higher peak (must break on a strictly higher cell).
- Trying right before left — the rules explicitly require left preference.
- Going past the strictly-lower-than-k cell when a lower cell exists further out (you want the LOWEST reachable, not the FIRST lower).
Follow-up questions
An interviewer at Airbnb may pivot to one of these next:
- Trapping Rain Water (LC 42) — same elevation map, different question.
- What if water could flow diagonally? (Different problem.)
- What if many sources poured simultaneously? (Sweep all sources per step.)
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why is left preferred over right?
The problem statement defines it that way — a tie-breaker. The physics doesn't actually care which side; the rule is for determinism.
Does this generalize to 2D pour water?
Conceptually yes — BFS from the drop point looking for the lowest reachable cell — but it's a much harder problem because flow can route around obstacles in many directions.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Pour Water and other Airbnb interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →