Loading...
You are given a list deployments where each element contains [start, end, servers], meaning one of a company's websites ran on servers machines from time start up to, but not including, time end. The company wants a chart of its largest deployment over time. Deployments overlap freely, and one that begins exactly when another ends does not overlap it.
At every moment the chart shows the server count of the largest deployment running at that moment, or 0 when nothing is running.
For deployments = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]] the five deployments, labeled A through E in input order, look like this:
servers
15 | BBBB
12 | CCCCCCC
10 | AAAAAAA DDDDD
8 | EEEEE
0 +---------------------------
0 5 10 15 20 25 time
Here A = [2,9,10], B = [3,7,15], C = [5,12,12], D = [15,20,10] and E = [19,24,8]. The chart of the largest deployment is:
servers
15 | +---+
12 | | +----+
10 | ++ | +----+
8 | | | | +---+
0 +--+---------+--+--------+--
0 5 10 15 20 25 time
Return the chart as a list of [time, servers] pairs sorted by time, with one entry for every moment the chart's value changes, paired with the new value. The chart always ends by dropping to 0 when the last deployment ends, and it never has two consecutive entries with the same value, because the value did not change there.
Reading the chart above from left to right, the value changes at time = 2, 3, 7, 12, 15, 20, 24, so the answer is [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]].
Deployments handing off at the same server count leave the chart flat, so nothing is recorded there. [[2,3],[4,5],[7,5],[11,5],[12,7]] is not a valid chart: the value is 5 all the way from time 4 to time 12, so only the change at 4 belongs in the list, giving [[2,3],[4,5],[12,7]].
Input: deployments = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]
Output: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]
Explanation: The deployments drawn above. A starts at time 2 with 10 servers. B
starts at 3 with 15 and the chart rises. B ends at 7 and the chart drops to 12,
because C is still running with 12 and A only has 10. A ending at 9 underneath C
changes nothing. C ends at 12 and nothing runs until D starts at 15 with 10. D
ends at 20 with E still running on 8, and E ends at 24.
Input: deployments = [[0,2,3],[2,5,3]]
Output: [[0,3],[5,0]]
Explanation: The second deployment starts exactly when the first one ends, with
the same server count, so the largest deployment has 3 servers the whole time
from 0 to 5. [[0,3],[2,3],[5,0]] is wrong: the value did not change at time 2.
deployments.length ≤104deployments[i].length =3start < end ≤231−1servers ≤231−1deployments is sorted by start in non-decreasing order.Click "Run" to test with sample cases or "Submit" to run all tests.