Finding kth smallest number from n sorted arrays

后端 未结 8 1152
谎友^
谎友^ 2020-12-02 06:31

So, you have n sorted arrays (not necessarily of equal length), and you are to return the kth smallest element in the combined array (i.e the combined array formed by mergin

8条回答
  •  天命终不由人
    2020-12-02 07:14

    If the k is not that huge, we can maintain a priority min queue. then loop for every head of the sorted array to get the smallest element and en-queue. when the size of the queue is k. we get the first k smallest .

    maybe we can regard the n sorted array as buckets then try the bucket sort method.

提交回复
热议问题