Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Algorithm to find the kth largest element in unsorted list

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I could write.



It has a bug. It is producing incorrect output for k=2. For k=1,3,4,5,6 , it is working fine.
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Here is what I could write.

Rather than prolong this too much, here's my solution. See if you follow it:it probably needs a check or two to make it bulletproof; but hopefully you get the general idea.

Winston

PS: So I lied; 30 lines, not 20.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I nailed it Winston. Here is my code:



I shall mark this as resolved now. Thanks all you guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic