Your question is Trapping Rain Water. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
ByteDance video analytics can represent a one-dimensional terrain profile as adjacent elevation bars. Given the bar heights, compute how many units of rainwater remain trapped after rainfall.
Each bar has width 1, and water can be trapped only where taller bars form boundaries on both sides. Return the total trapped volume.
Implement trap_rain_water(height), where height is a list of non-negative integers. Return an integer representing the total trapped water. The function must run in linear time and use constant auxiliary space.
def trap_rain_water(height):