Sum of n time series - Onsite Question
Anonymous User
2508

Got asked this question to solve. There are n arrays and we need to find the sum of the values at a particular time in all the arrays.
We need to keep picking the values of the smallest times in all the input array and add the sum at that time in all the inputs.

Eg:
[(0,1),(5,3),(6,7)]
[(0,1),(3,6),(4,7)]
Output:
[(0,2),(3,7),(4,8),(5,9),(6,14)]
If (0,1) and (5,3) are inputs in arrays. Then the value from till 0 - 4 is 1. And after 5, it is 3.

Struggled to find an optimal solution to this one specially for extending to n input arrays.
I suggested a priority queue solution similar to Merge k sorted lists, but wasnt able to code in time. Can someone suggest how this could be solved?

Comments (3)