Skip to content

Instantly share code, notes, and snippets.

@jsbonso
Created December 15, 2018 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsbonso/29d32c318cdd30a02f5001e086ebf856 to your computer and use it in GitHub Desktop.
Save jsbonso/29d32c318cdd30a02f5001e086ebf856 to your computer and use it in GitHub Desktop.
Kth Element
Write a method that finds k-th most common element in a list. For example, kthMostCommon(new in[]{5, 4, 3, 2, 1, 5, 4, 3, 2, 5, 4, 3, 5, 4, 5},2) should return 4. In the array, element 1 occurs once, 2 twice, 3 three times, 4 fours times, and 5 five times, making element 5 the most common element in the list and 4th the second most common element,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment