Skip to main content

2137. Pour Water Between Buckets to Make Water Levels Equal

mediumAsked at Airbnb

You have n buckets with water; you may pour from i to j but lose a fraction loss/100 in transit. Maximize the equal level achievable. Airbnb asks this to test binary search on a continuous answer plus a feasibility check.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Airbnb loops.

  • Glassdoor (2026-Q1)Airbnb senior onsite reports list this as a recurring binary-search-on-answer medium.
  • Blind (2025-10)Mentioned in Airbnb L5 algorithm interviews.

Problem

You have n buckets each containing some gallons of water in it, represented by a 0-indexed integer array buckets, where the ith bucket contains buckets[i] gallons of water. You are also given an integer loss. You want to make the amount of water in each bucket equal. You can pour any amount of water from one bucket to another (possibly different) bucket. However, every time you pour k gallons of water, only k * ((100 - loss) / 100) gallons make it to the destination bucket. Return the maximum amount of water in each bucket after making the amounts equal. Answers within 10^-5 of the actual answer will be accepted.

Constraints

  • 1 <= buckets.length <= 10^5
  • 0 <= buckets[i] <= 10^5
  • 0 <= loss <= 99

Examples

Example 1

Input
buckets = [1,2,7], loss = 80
Output
2.00000

Explanation: Pour 5 from bucket 2; bucket 0 gains 5 * 20% = 1, ending at 2. All equal.

Example 2

Input
buckets = [2,4,6], loss = 50
Output
3.50000

Example 3

Input
buckets = [3,3,3,3], loss = 40
Output
3.00000

Approaches

1. Binary search on the answer (optimal)

The answer is monotonic — if a level L is achievable, so is any smaller level. Binary search L over [0, max(buckets)]. Check feasibility by accounting source supply vs sink demand at level L.

Time
O(n log(max / eps))
Space
O(1)
function equalizeWater(buckets, loss) {
  const remain = (100 - loss) / 100;
  function feasible(level) {
    let supply = 0, demand = 0;
    for (const b of buckets) {
      if (b > level) supply += (b - level);
      else demand += (level - b);
    }
    return supply * remain >= demand;
  }
  let lo = 0, hi = Math.max(...buckets);
  for (let i = 0; i < 100; i++) {
    const mid = (lo + hi) / 2;
    if (feasible(mid)) lo = mid;
    else hi = mid;
  }
  return lo;
}

Tradeoff: Binary search on a real-valued answer with a fixed number of iterations (100 is enough for 1e-5 precision). The feasibility check is linear; total cost dominated by 100 * n.

2. Sort-and-balance (incorrect for arbitrary input)

Sort buckets and try to fill the lowest from the highest. Doesn't always reach the optimum because pours don't have to follow neighbors.

Time
O(n log n)
Space
O(n)
// Intentionally incorrect — kept to show why binary search is the right tool.
function sortAndBalance(buckets, loss) {
  // Sorting and greedy pouring works in some cases but not all.
  // Counter-example: [1, 100, 1] with high loss — optimal isn't reachable by neighbor pours.
  return -1;
}

Tradeoff: Useful only as a teaching foil. Reach for the binary-search framing instead.

Airbnb-specific tips

Airbnb's bar on this is the monotonic-feasibility argument: 'If I can achieve level L, I can achieve any lower L' too (just stop pouring earlier). That monotonicity unlocks binary search on the answer. Without articulating monotonicity, the feasibility check looks unmotivated.

Common mistakes

  • Confusing the supply/demand sides — at level L, sources are buckets above L; sinks are buckets below L.
  • Forgetting that only (1 - loss/100) of poured water arrives at the sink — the loss is on the source side.
  • Using too few binary-search iterations; 50 may not hit 1e-5 precision; use 100.

Follow-up questions

An interviewer at Airbnb may pivot to one of these next:

  • What if loss varied per pour (e.g., distance-dependent)?
  • What if buckets had max capacities? (Add capacity constraint to feasibility.)
  • Capacity to ship packages within D days (LC 1011) — same binary-search-on-answer template.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why binary search instead of an analytical formula?

An analytical formula exists for fixed loss but binary search is robust: any feasibility function that's monotonic gives the answer in O(log) iterations regardless of formulas.

How many iterations are enough?

Each iteration halves the interval. Starting from hi - lo = 1e5, you need ~34 iterations to hit 1e-5. 100 is overkill but takes microseconds.

Free learning resources

Curated free links for this problem.

Practice these live with InterviewChamp.AI

Drill Pour Water Between Buckets to Make Water Levels Equal 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 →