Imagine you're a city planner analyzing building heights along a perfectly straight street! ๐๏ธ
You're given a 2D array buildings where each buildings[i] = [start, end, height] represents a building with height covering the half-closed interval [start, end) on the street.
Your task is to divide the street into segments where each segment has a constant average building height. Return these segments as [[left, right, average], ...] using the minimum number of non-overlapping segments.
Key Points:
- Half-closed interval
[a, b)includesabut excludesb - Average is calculated using integer division
- Only include segments where buildings exist
- Segments can be returned in any order
Example: If buildings = [[1,5,2],[3,10,4]]
โ Street segments: [[1,3,2], [3,5,3], [5,10,4]]
โ From 1-3: only first building (avg = 2/1 = 2)
โ From 3-5: both buildings (avg = (2+4)/2 = 3)
โ From 5-10: only second building (avg = 4/1 = 4)
Input & Output
Constraints
- 1 โค buildings.length โค 1000
- buildings[i].length == 3
- 0 โค starti < endi โค 108
- 1 โค heighti โค 1000
- Half-closed intervals: [start, end) includes start but excludes end