As reported: Visa DSA interview 1 (2025): two questions — trapping rain water, rephrased as sand settling between mountains, and the sliding window maximum.
height[i] is the height of a mountain column of width 1 at position i. Sand (or rain water) is poured over the whole range and settles in the valleys; anything above the lower of the two surrounding peaks spills off the ends. Return the total amount that stays.
This is LeetCode 42 — Trapping Rain Water.
Example
height = [0,1,0,2,1,0,1,3,2,1,2,1] -> 6
height = [4,2,0,3,2,5] -> 9
Constraints: 1 ≤ height.length ≤ 2·10^4; 0 ≤ height[i] ≤ 10^5.
Code runner format: one JSON value per line: height. Implement trap(height); the harness prints the amount.