The Average Height of Buildings in Each Segment interview question involves a set of buildings, each defined by a start position, an end position, and a height. Buildings can overlap. You need to divide the entire range into non-overlapping segments where the average height of buildings covering that segment is constant. This Average Height of Buildings in Each Segment coding problem is a coordinate-based sweep-line task.
Microsoft uses this to test a candidate's ability to handle interval-based data. It requires understanding how to "sweep" across a number line, tracking the cumulative sum of heights and the count of active buildings at every transition point. It's a more complex variation of the "Meeting Rooms" or "Skyline" problem.
This utilizes the Array, Sorting, Heap (Priority Queue), Prefix Sum interview pattern, specifically the Sweep Line algorithm.
Building 1: [1, 5, height 10], Building 2: [3, 8, height 20].
Master the "Difference Array" or "Sweep Line" technique. It is the go-to pattern for any problem involving intervals, overlaps, or changes in state across a 1D timeline.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Zero Array Transformation III | Medium | Solve | |
| Car Pooling | Medium | Solve | |
| Single-Threaded CPU | Medium | Solve | |
| Campus Bikes | Medium | Solve | |
| Choose K Elements With Maximum Sum | Medium | Solve |