Trapping Rain Water

Trapping Rain Water

Given an array of n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. For example, given [0,1,0,2,1,0,1,3,2,1,2,1], the output should be 6. Constraints: 1 \le n \le 2 \times 10^4 0 \le height[i] \le 10^5
JavaTwo Pointers
00
Read

Trapping Rain Water

Given an array of non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Constraints: n == height.length 1 <= n <= 2 * 10^4 0 <= height[i] <= 10^5
JavaTwo Pointers
00
Read

Trapping Rain Water

Given an array of non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Constraints: n == height.length 1 <= n <= 2 * 10^4 0 <= height[i] <= 10^5 Your solution should aim for linear time complexity O(n) and constant space complexity O(1).
JavaTwo Pointers
00
Read

Trapping Rain Water

Given an array of n non-negative integers representing an elevation map where the width of each bar is 1, calculate the total volume of water it can trap after a rainstorm. Example: Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] Output: 6 Explanation: The elevation map is represented by the array. In this case, 6 units of rain water are being trapped. Constraints: n == height.length 1 \le n \le 2 \times 10^4 0 \le height[i] \le 10^5
JavaTwo-Pointer Technique
00
Read
1
InterviewGPT

AI-powered tools to help you succeed in tech interviews — from resume to offer.

Interview Solver

  • Coding Puzzles
  • System Design
  • Behavioral Challenges
  • ML System Design
  • SQL Puzzles
  • FE System Design
Explore Solver

Question Bank

  • Coding Interview Questions
  • System Design Interview Questions
  • Behavioral Interview Questions
  • ML System Design Questions
  • SQL & Database Questions
  • FE System Design Questions
Explore Questions

Golden Blogs

  • Coding Solutions
  • System Design Guides
  • Behavioral Guides
  • ML System Design Guides
  • SQL Solutions
  • FE System Design Guides
Explore Blogs

Intervipedia

  • Coding Concepts
  • System Design Concepts
  • Behavioral Concepts
  • ML System Concepts
  • SQL Concepts
  • FE System Concepts
Explore Concepts

Application Tools

  • Self-Intro Generator

Company

  • Pricing
  • FAQ
  • About
  • Privacy Policy
  • Terms of Service

© 2026 InterviewGPT Inc. All rights reserved.

All systems operationalUS-East

Made with ♥ for developers