Pick Two Rack Walls That Hold the Most Cooling Water

Last updated: November 29, 2026

Quick Overview

Given heights of vertical walls placed at unit spacing along a data center aisle, choose two walls that, together with the floor, hold the largest volume of water, and return that volume.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given heights of vertical walls placed at unit spacing along a data center aisle, choose two walls that, together with the floor, hold the largest volume of water, and return that volume.

A two pointer classic placed in a Meta infrastructure framing. The interviewer is testing whether you can justify the greedy move (always advance the shorter wall), not just recall it.

What the Interviewer Expects
  • States the O(n^2) pair scan as a baseline
  • Starts with the widest pair and moves the shorter wall inward
  • Proves that moving the taller wall can never improve the answer
  • Distinguishes this problem from trapped rainwater, where every bar holds water
  • Gives O(n) time and O(1) space
Key Topics to Cover
two pointers
greedy proof
container with most water
array
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How does the answer change if walls have non-uniform positions given as (x, height) pairs?
  • Return the indices of the best pair, breaking ties by the narrowest width.
  • Why does the same greedy argument fail if water may sit on top of intermediate walls?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: heights, a list of non-negative integers, length n >= 2. The volume between walls i < j is (j - i) * min(heights[i], heights[j]). Intermediate walls do not block anything. Output: the max...

High-Level Design

Start with i = 0 and j = n-1, the widest container. Its volume is limited by the shorter wall. Any container that keeps the shorter wall and moves the other one inward is narrower and still capped...


Submit Your Answer
Markdown supported