Building Shadow Calculator - Problem
You are given an array of integers representing the heights of buildings in a row. The buildings are illuminated by a light source positioned to the left of all buildings, casting shadows to the right.
Each building casts a shadow with length equal to its height. However, if a building is blocked by a taller building to its left, it won't cast any shadow (the taller building's shadow covers it completely).
Calculate the total length of all visible shadows cast to the right.
Example: For buildings [3, 1, 4, 1, 5], only buildings with heights 3, 4, and 5 cast shadows (heights 3→4→5 are increasing from left). The two buildings with height 1 are blocked. Total shadow length = 3 + 4 + 5 = 12.
Input & Output
Constraints
- 1 ≤ heights.length ≤ 104
- 1 ≤ heights[i] ≤ 109