Find common elements in k sorted lists (assuming they can have duplicate values) in constant space

Viewed 1848

I was wondering what is the most efficient solution to find intersection of k sorted lists of integers (assuming that they can have duplicates). I have already came up with a few solutions. But I was wondering if there is any way to do it in constant space and with best time complexity?

Ex:
for k=4
[[1,2,3,3,4],[2,3,3,5],[1,2,3,3,5,6,7],[1,2,3,3,6,7,8,9]]
should return [2,3,3]
5 Answers
Related