2142. Average Height of Buildings in Each Segment

Medium
Array
Greedy
Sorting
Heap (Priority Queue)

Description

Hints

Hint 1
Try sorting the start and end points of each building.
Hint 2
The naive solution is to go through each position on the street and keep track of the sum of all the buildings at that position and the number of buildings at that position.
Hint 3
How could we optimize that solution to pass?
Hint 4
We don't need to go through every position, just the ones where a building starts or a building ends.

Statistics

Acceptance
58.2%
Submissions
4,593
Accepted
2,672