Tap here to switch tabs
Problem
Submissions

Problem: Average Height of Buildings in Each Segment

Try to solve the Average Height of Buildings in Each Segment problem.

Statement

You are given a 22D integer array buildings where buildings[i] =[= [start_i, end_i, height_i]] denotes that the ithi^{ {th}} building exists along the half open interval [[start_i, end_i)) with a height of height_i.

The average height of a segment is defined as the total sum of heights of all buildings present in that segment divided by the total number of buildings in that segment, rounded down to the nearest integer.

Return a sorted list of non overlapping segments [[start, end, avg_height]] sorted by start in ascending order such that:

  • Every point within [[start, end)) is covered by at least 11 building.

  • The average height avg_height is identical for all points within [[start, end)).

  • There are no two adjacent segments with the same average height that share a boundary point (adjacent segments with the same average height must be merged into a single segment).

  • Intervals with no buildings are omitted from the output.

Constraints:

  • 1≤1 \leq buildings.length ≤105\leq 10^5

  • buildings[i].length =3= 3

  • 0≤0 \leq start_i << end_i ≤108\leq 10^8

  • 1≤1 \leq height_i ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Average Height of Buildings in Each Segment

Try to solve the Average Height of Buildings in Each Segment problem.

Statement

You are given a 22D integer array buildings where buildings[i] =[= [start_i, end_i, height_i]] denotes that the ithi^{ {th}} building exists along the half open interval [[start_i, end_i)) with a height of height_i.

The average height of a segment is defined as the total sum of heights of all buildings present in that segment divided by the total number of buildings in that segment, rounded down to the nearest integer.

Return a sorted list of non overlapping segments [[start, end, avg_height]] sorted by start in ascending order such that:

  • Every point within [[start, end)) is covered by at least 11 building.

  • The average height avg_height is identical for all points within [[start, end)).

  • There are no two adjacent segments with the same average height that share a boundary point (adjacent segments with the same average height must be merged into a single segment).

  • Intervals with no buildings are omitted from the output.

Constraints:

  • 1≤1 \leq buildings.length ≤105\leq 10^5

  • buildings[i].length =3= 3

  • 0≤0 \leq start_i << end_i ≤108\leq 10^8

  • 1≤1 \leq height_i ≤105\leq 10^5