FastPrepTrapping Rain Water
Problems/Trapping Rain Water

Trapping Rain Water

Google logoGoogle● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand March 2026 review of a Google Software Engineer internship names this exact well-known problem as one of three online-test questions. Our version is about 99% the same as the named task.

You are given n non-negative integers representing an elevation map. Each bar has width 1.

Return how many units of rain water the elevation map can trap.

Function

trap(height: int[]) → int

Examples

Example 1

height = [0,1,0,2,1,0,1,3,2,1,2,1]return = 6

The bars trap a total of 6 units of water.

Example 2

height = [4,2,0,3,2,5]return = 9

The elevation map traps 9 units in total.

Example 3

height = [1,2,3]return = 0

A strictly increasing elevation map cannot trap water.

Constraints

  • 1 <= height.length <= 20000.
  • 0 <= height[i] <= 100000.

More Google Online Assessment questions

  • Minimum Operations to Make a SubsequenceOA · Seen Nov 2026
  • Book Reading EveningsOA · Seen Nov 2026
  • Count Score CategoriesOA · Seen Nov 2026
  • Minimum Cars for Rental RequestsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Shortest Path in a Binary MatrixOA · Seen Nov 2026
  • Robot Assembly Line ConflictsOA · Seen Oct 2026
  • Assign LockerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Biggest Number From DigitsOA · Seen Oct 2026
  • Consolidate On-Call RotationsOA · PHONE SCREEN · Seen Oct 2026
  • Decreasing SubsequencesOA · Seen Sep 2026

Similar questions at other companies

  • Trapping Rain WaterMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Rain Kept Between WallsDocuSign · PHONE SCREENDocuSign interview questions
  • Rain Water Held Between BarsAdobe · PHONE SCREENAdobe interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Alternating Jumps to the Last IndexExpedia · OAExpedia interview questions
  • Trapping Rain WaterTeradata · ONSITE INTERVIEW
  • Trapping Rain WaterBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Trapping Rain WaterOracle · PHONE SCREENOracle interview questions
  • Trapping Rain WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Trapping Rain WaterKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions

Interview reports that mention this question

  • Google OA: What It Tests (2026)
  • Google SWE Intern OA and Interviews: 42 Experiences (Part 1 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int trap(int[] height) {
        // Write your code here.
    }
}
Checking account…