−65% Most banks now $169 $59.
Coding · 7 min read

Airbnb's Terrain Water-Drop Coding Question

Airbnb loves a problem you can picture. This terrain water-drop question is a recurring on-site: first you render a heightmap, then you simulate water physics as drops settle into the lowest reachable ground. Here is the full question, Java for both parts, and the rubric.


The question

Part 1: given column heights, render the terrain with + for filled cells. Part 2: drop a number of water units at a column; each unit flows to the lowest reachable neighbor (left preferred, then right) and settles, like the classic pour-water problem.

heights = [5,4,3,2,1,3,4,0,3,4]
dumpWater(heights, amount=8, column=1)

Part 1 · Render the terrain

Scan from the tallest level down to 1. On each row, a column is filled if its height reaches that level. This warm-up also fixes your mental model of the grid for Part 2.

import java.util.*;

class Terrain {
    // Part 1: each row is one height level, top to bottom.
    List<String> render(int[] heights) {
        int maxH = 0;
        for (int h : heights) maxH = Math.max(maxH, h);
        List<String> rows = new ArrayList<>();
        for (int level = maxH; level >= 1; level--) {
            StringBuilder row = new StringBuilder();
            for (int colH : heights) row.append(colH >= level ? '+' : ' ');
            rows.add(row.toString());
        }
        return rows;
    }
}

Part 2 · Drop the water

For each unit of water released at the spring column, try to flow left to the lowest reachable position; if it cannot fall left, try right; otherwise it settles where it is. The effective height of a column is terrain plus water already resting there.

int[] pourWater(int[] heights, int amount, int spring) {
    for (int drop = 0; drop < amount; drop++) {
        int pos = flow(heights, spring, -1);      // try to fall left first
        if (pos == spring) pos = flow(heights, spring, +1);  // else right
        heights[pos]++;                            // settle one unit here
    }
    return heights;
}

// Walk in 'dir' while the next cell is not higher; return the lowest reachable
// position, breaking ties toward the cell closest to the spring.
private int flow(int[] h, int start, int dir) {
    int pos = start, best = start;
    while (pos + dir >= 0 && pos + dir < h.length && h[pos + dir] <= h[pos]) {
        pos += dir;
        if (h[pos] < h[best]) best = pos;
    }
    return best;
}

The left-before-right rule and the tie-break toward the spring are the whole game. Get them wrong and the water settles in the wrong valley. Complexity is O(amount x n) in the worst case, which is the trade-off to name.

How Airbnb scores it

Dimension Weak Strong
RenderingOff-by-one rows or columnsCorrect top-down heightmap
Flow rulesIgnores left-before-right or tiesLeft first, then right, settle at lowest, tie toward spring
State modelForgets water already settledEffective height = terrain + water
Edge casesWalks off the array, mishandles flat groundBounds-checked, handles plateaus
ComplexityCannot state the costStates O(amount x n) and when it matters

This is one question of 40 pages

Get the full Airbnb question bank

The full Airbnb bank carries the coding and code-review rounds, each problem with its follow-ups and a rubric, compiled from people familiar with the process and cross-verified across sources.

Airbnb interview FAQ

What does the Airbnb coding interview ask?+

Concrete, visual simulation and array problems you can reason about on a whiteboard, often with a rendering step and then a physics or state-update step. Clarity and correct edge handling matter as much as speed.

Is the Airbnb interview LeetCode-style?+

It draws on similar patterns (arrays, simulation, the pour-water problem) but favors readable code and clear reasoning about how state evolves over raw trick-spotting.

How is the Airbnb coding round scored?+

On a correct simulation that respects the flow rules (left before right, settle at the lowest reachable point), clean rendering, edge cases at the boundaries and on flat ground, and stated complexity.

Where can I find real Airbnb interview questions?+

Pichup maintains a 40-page Airbnb question bank compiled from people familiar with the process, with the coding and review rounds, their follow-ups, and rubrics. The question in this guide is one of them.