Problem
Given n non-negative integers representing an elevation map, compute how much water it can trap after raining.
Solution: Two Pointers
python
1def trap(height: List[int]) -> int:2 left, right = 0, len(height) - 13 left_max = right_max = 04 water = 05 6 while left < right:7 if height[left] < height[right]:8 left_max = max(left_max, height[left])9 water += left_max - height[left]10 left += 111 else:12 right_max = max(right_max, height[right])13 water += right_max - height[right]14 right -= 115 16 return waterTime: O(n) | Space: O(1)