← 返回 uber 的题目列表Merge Step Functions of (timestamp, value) Pairs
类型:qbank
Given two step functions over time, each encoded as sorted [timestamp, value] checkpoints, return the checkpoints of their pointwise sum. The follow-up extends the merge to k functions via divide-and-conquer.
Examples
Example 1:
Input: a = [[1,3],[3,1],[5,3],[6,4],[10,1]], b = [[2,3],[6,3],[11,2]]
Output: [[1,6],[2,4],[3,4],[5,6],[6,7],[10,3],[11,2]]
Explanation:
At each timestamp from the union of checkpoints, sum the active value of a and b. After timestamp 10, a is exhausted and contributes 0, so the final entry inherits b's value 2.
Example 2:
Input: a = [[5,1]], b = [[5,2]]
Output: [[5,3]]
Explanation:
Both functions end at the same timestamp. Emit one merged entry with the summed value.
Example 3:
Input: a = [], b = [[1,7],[4,2]]
Output: [[1,7],[4,2]]
Explanation:
When one array is empty, the merged function is just the other array.
Constraints
0 <= a.length, b.length <= 10^5
a[i].length == b[j].length == 2
0 <= a[i][0], b[j][0] <= 10^9 (timestamps)
-10^4 <= a[i][1], b[j][1] <= 10^4 (values)
Within each input array, timestamps are strictly increasing.