As reported: Apple IS&T backend engineer (Java / Spring Boot, Hyderabad, 2025), elimination round 1: 30 minutes of DSA — trapping rain water — then 30 minutes of Java and Spring Boot theory.
Given 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.
This is LeetCode 42 — Trapping Rain Water.
Example 1
height = [0,1,0,2,1,0,1,3,2,1,2,1] -> 6
Example 2
height = [4,2,0,3,2,5] -> 9
Constraints: 1 ≤ n ≤ 2 · 10^4; 0 ≤ height[i] ≤ 10^5.
Code runner format: one JSON value per line: height (LeetCode's test-case format). Implement trap(height); the harness prints the amount of water.