Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Trapping Rain Water

Python data engineering interview problem. Difficulty: intermediate. Pattern: Two Pointers. About 10 minutes. Part of the Pro drill bank.

How much rainwater can be trapped between bars. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement trap_rain_water(height: list) -> int returning trapped water units.

Constraints

  • Non-negative heights.
  • Intermediate difficulty: O(n) two-pointer solution preferred.

Examples

Input: trap_rain_water([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]) Output: 6 Water pools in the valleys.

Topics: lakebench, python, water, two pointers.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Trapping Rain Water

Interview-style drill: How much rainwater can be trapped between bars.

Implement `trap_rain_water(height: list) -> int` returning trapped water units. Example: `[0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]` → `6`. Keep the harness.