Sunday, April 29, 2012

Find the kth smallest element in a (MxN) matrix.

PS:Think how efficiently u can do same for an array .

3 comments :

nutr0n said...

We can use an auxiliary array.. we can copy all the elements of the mxn matrix to that auxiliary linear array and apply quick select algorithm.. complexity would be O(mxn)..

Shwetank said...
This comment has been removed by the author.
Shwetank said...

-Convert the input matrix(m*n) in to Yongify matrix [Sorted rows and colums)
- Apply Youngify 'k' times

Time Complexity: O(mnlogn) + O(mnlogm) + O(k*(m+n))