What is the most efficient way of getting the intersection of k sorted arrays?
6
2
Given k sorted arrays what is the most efficient way of getting the intersection of these lists Ex INPUT: [[1,3,5,7], [1,1,3,5,7], [1,4,7,9]] Output: [1,7] There is a way to get the union of k sorted arrays based on what I read in the Elements of programming interviews book in nlogk time. I was wondering if there is a way to do something similar for the intersection as well ## merge sorted arrays in nlogk time [ regular appending and merging is nlogn time ] import heapq def mergeArys(srtd_arys): heap = [] srtd_iters = [iter(x) for x in srtd_arys] # put the first element from each srtd array onto the heap for idx, it in enumerate(srtd_iters): elem = next(it, None) if elem: heapq.heappush(heap, (elem, idx)) ...