"Coding is just like talking to a unknown girl. Once you talked to her with guts, the next time you'll never afraid",Really? Yes , try it Now !!!
Everything here is for education and learning purpose only , individual holds rights on outer posts/links etc.
Team Cracking The Code
About Me
▼
Sunday, April 29, 2012
Find the kth smallest element in a (MxN) matrix.
PS:Think how efficiently u can do same for an array .
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)..
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)..
ReplyDeleteThis comment has been removed by the author.
ReplyDelete-Convert the input matrix(m*n) in to Yongify matrix [Sorted rows and colums)
ReplyDelete- Apply Youngify 'k' times
Time Complexity: O(mnlogn) + O(mnlogm) + O(k*(m+n))