You are given k sorted lists (or linked lists) of records. Each record has:
timestamp
(integer)
values
(an array of integers sorted in non-decreasing order)
Each individual list is sorted by timestamp in non-decreasing order.
Your task is to merge the k lists into one sorted list by timestamp, with the following special rule:
timestamp
, you must
coalesce
them into a
single output record
with that timestamp.
values
array of the coalesced record is the
sorted merge
of all
values
arrays from records with that timestamp.
Return the merged list of records sorted by timestamp.
lists
: an array of length
k
, where each element is a list of records
(timestamp, values)
sorted by
timestamp
.
(timestamp, values)
sorted by
timestamp
, where each timestamp appears at most once.
0 <= k <= 10^4
N
(up to ~10^5)
values
arrays:
M
(up to ~10^5)
Input:
(1,[1,4]) -> (3,[2])
(1,[0,5]) -> (2,[7])
(3,[3,3])
Output:
(1,[0,1,4,5]) -> (2,[7]) -> (3,[2,3,3])
(Notice timestamps 1 and 3 are merged first across lists, and their values arrays are merged into one sorted array.)