How to find pair with kth largest sum?

前端 未结 6 875
深忆病人
深忆病人 2020-12-02 12:29

Given two sorted arrays of numbers, we want to find the pair with the kth largest possible sum. (A pair is one element from the first array and one element from the second

6条回答
  •  生来不讨喜
    2020-12-02 13:26

    The max-heap algorithm in the other question is simple, fast and correct. Don't knock it. It's really well explained too. https://stackoverflow.com/a/5212618/284795

    Might be there isn't any O(k) algorithm. That's okay, O(k log k) is almost as fast.

提交回复
热议问题