tents[i] = [start, end, height] has height height and covers the half-open interval [start, end): the point start is included and the point end is not. Tents may overlap.
For each point of the road covered by at least one tent, define its average height: the sum of the heights of all tents over it, divided by their count with integer division.
Describe the road with the fewest non-overlapping pieces [left, right, average], where the average height is average everywhere on [left, right). Adjacent pieces that touch and share the same average must be merged into one. Stretches with no tents are left out of the answer.
The pieces may be returned in any order.tents=[[0, 6, 3], [4, 8, 6]] → [[0, 4, 3], [4, 6, 4], [6, 8, 6]]
On [0, 4) there is only the first tent, average 3. On [4, 6) both: (3 + 6) // 2 = 4. On [6, 8) only the second, 6.
tents=[[1, 3, 5], [2, 4, 4], [2, 4, 6]] → [[1, 4, 5]]
[1, 2): 5. [2, 3): (5 + 4 + 6) // 3 = 5. [3, 4): (4 + 6) // 2 = 5. The average is 5 everywhere and the pieces touch, so they merge into one.
tents=[[0, 2, 7], [5, 9, 7]] → [[0, 2, 7], [5, 9, 7]]
There are no tents between 2 and 5, so the two pieces with average 7 stay separate.
tents=[[0, 6, 3], [4, 8, 6]]
[[0, 4, 3], [4, 6, 4], [6, 8, 6]]
Run checks the first 3 tests in your browser. Submit checks all 111 tests on the server, hidden ones included.