Find the K largest element in a sorted M*N array# JobHunting - 待字闺中
m*q
1 楼
Looks like an old question, but failed to find a better solution than O(klg(
m+n)). Any ideas?
The question is quoted from a comment on ihas1337code website
------
1.Two reverse sorted arrays A and B have been given. such that size of A is
m and size of B is n
You need to find the k th largest sum (a+b) where a is taken from A and b is
taken from B. such that k < m*n It can be done in O(n*n) but i believe it
can be done in a very efficient way. I heard someone say there is a paper
from SODA. It's possible to solve it in O(N), however, it requires very
complex algorithm. I am wondering if you can come up with an NlogN algorithm
first then try O(N). These two problems have been very hot interview
problems from Google, however, not many people can solve it very efficiently
yet. I believe you can do it after I read many posts on your site.
2. Given a N*N Matrix. All rows are sorted, and all columns are sorted. Find
the Kth Largest element of the matrix.
m+n)). Any ideas?
The question is quoted from a comment on ihas1337code website
------
1.Two reverse sorted arrays A and B have been given. such that size of A is
m and size of B is n
You need to find the k th largest sum (a+b) where a is taken from A and b is
taken from B. such that k < m*n It can be done in O(n*n) but i believe it
can be done in a very efficient way. I heard someone say there is a paper
from SODA. It's possible to solve it in O(N), however, it requires very
complex algorithm. I am wondering if you can come up with an NlogN algorithm
first then try O(N). These two problems have been very hot interview
problems from Google, however, not many people can solve it very efficiently
yet. I believe you can do it after I read many posts on your site.
2. Given a N*N Matrix. All rows are sorted, and all columns are sorted. Find
the Kth Largest element of the matrix.