Compute Coolant Trapped Between Uneven Server Rack Heights

Last updated: November 29, 2026

Quick Overview

Given an array of non-negative integers representing the heights of server racks in a row (each one unit wide), compute how many units of liquid would pool between them after a coolant spill fills every gap that has a taller rack on both sides.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given an array of non-negative integers representing the heights of server racks in a row (each one unit wide), compute how many units of liquid would pool between them after a coolant spill fills every gap that has a taller rack on both sides.

A two pointer Hard problem in the style Microsoft onsites use to separate strong candidates. The datacenter framing is light; the interviewer wants you to derive the min of left max and right max rule, then remove the extra arrays with two converging pointers.

What the Interviewer Expects
  • State the per-cell rule: water = min(maxLeft, maxRight) - height
  • Give the O(n) space prefix and suffix maximum solution
  • Improve to O(1) space with two pointers
  • Justify moving the pointer on the side with the smaller max
  • Test flat, ascending and V-shaped inputs
Key Topics to Cover
two pointers
prefix maximum
arrays
monotonic stack
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 would you solve the 2D version on a grid of rack heights?
  • Can you solve it with a monotonic stack and explain how it accumulates water?
  • What if racks have different widths?
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: list h of n non-negative integers. Output: total trapped units. A cell i holds min(max(h[0..i]), max(h[i..n-1])) - h[i] units, which is never negative because each max includes h[i] itsel...

High-Level Design

The straightforward method precomputes left_max and right_max arrays and sums the rule per cell, O(n) time and O(n) space. To drop the arrays, run two pointers from both ends with running maxima `...


Submit Your Answer
Markdown supported