FastPrepRain Kept Between Walls
Problems/Rain Kept Between Walls

Rain Kept Between Walls

DocuSign logoDocuSign● HardINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from March 2026 describes the first technical round after the online test. The candidate solved this trapped-rain task, first with a slow version and then with two pointers. Edge cases and a 2D grid version came up in the talk.

The report gives no input format, limits or examples. Here you get one array of wall heights, with 1 to 10,000 walls and heights from 0 to 10,000. Water runs off both ends of the row. The editorial explains the 2D grid version, but it is not tested. We wrote the examples.

Our version is about 90% the same as the reported question.

You are given a row of walls. Wall i is 1 unit wide and walls[i] units tall. The walls stand side by side with no gaps.

Rain falls on the whole row. Above wall i, water rises to the lower of two heights:

  • the tallest wall from the first wall up to wall i, and
  • the tallest wall from wall i up to the last wall.

So wall i keeps that level minus walls[i] units of water. Water runs off both ends of the row, so a wall with nothing taller on one side keeps no water.

Return the total units of water kept on top of all the walls.

Function

rainKept(walls: int[]) → int

Examples

Example 1

walls = [3,0,2,0,4]return = 7

The tallest wall on the left of the middle part is 3 and on the right is 4, so water rises to the lower one, level 3. Above the walls of height 0, 2 and 0 that is 3 + 1 + 3 = 7 units.

Example 2

walls = [5,4,1,2]return = 1

Only the wall of height 1 holds water. Its tallest wall on the left is 5 and on the right is 2, so the water rises to 2 and holds 1 unit. The wall of height 4 has nothing taller than 4 on its right, so it holds nothing. The answer is 1.

Example 3

walls = [0,3,0,1,0]return = 1

The first 0 has no wall on its left, so water runs off that end. The 0 between 3 and 1 fills up to 1, the lower side: 1 unit. The last 0 has no wall on its right, so it holds nothing. The answer is 1.

Constraints

  • 1 <= walls.length <= 10^4
  • 0 <= walls[i] <= 10^4

More DocuSign Phone Screen questions

  • Symmetric Binary TreePHONE SCREEN · Seen Oct 2026
  • Union Area of Two RectanglesPHONE SCREEN · Seen Oct 2026
  • Execute Cursor-Based Text Editor OperationsPHONE SCREEN · Seen Sep 2026
  • Minimize Array Sum After K Halving OperationsPHONE SCREEN · Seen Sep 2026
  • Fizz and Buzz Words From 1 to nPHONE SCREEN · Seen Sep 2026
  • Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Rebuild a Trip From Flight TicketsPHONE SCREEN · Seen Apr 2019
  • Find the Words for Each PrefixPHONE SCREEN · Seen Sep 2018

Similar questions at other companies

  • Rain Water Held Between BarsAdobe · PHONE SCREENAdobe interview questions
  • Trapping Rain WaterMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Trapping Rain WaterGoogle · OAGoogle interview questions
  • 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
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Trapping Rain WaterKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Trapping Rain WaterNuro · ONSITE INTERVIEWNuro interview questions
  • Trapping Rain WaterRupeek · ONSITE INTERVIEW

Interview reports that mention this question

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)
  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public int rainKept(int[] walls) {
        // Write your code here.
    }
}
Checking account…