Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

height =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Water above a bar is limited by the tallest bar to its left and right.

Approach

Use two pointers and track left_max and right_max.

  • If height[l] < height[r], the right side is tall enough to bound l, so we can finalize water at l using left_max.
  • Otherwise finalize water at r using right_max.

Why it works

The smaller side determines the current bounding height; the opposite side is guaranteed to be at least as high as the smaller boundary for that step.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Water above a bar is limited by the tallest bar to its left and right.

Approach

Use two pointers and track left_max and right_max.

  • If height[l] < height[r], the right side is tall enough to bound l, so we can finalize water at l using left_max.
  • Otherwise finalize water at r using right_max.

Why it works

The smaller side determines the current bounding height; the opposite side is guaranteed to be at least as high as the smaller boundary for that step.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)