• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding top 3 repeated numbers in an array  RSS feed

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an int array which has only integer values in it. I need to find top 3 repeated numbers in it with minimum time/space complexity. Please let me know how can we do this.

example: if array is {3,8,2,4,6,65,34,3,8,4,98,23,54,3,8,65,3}, then output is:

3 is repeated 4 times
8 is repeated 3 times
4 is repeated 2 times
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a sheet of paper, a pencil and an eraser. The last is the most important tool. You write down exactly how you intend to do it, and you keep simplifying it until you have got it down to words of one syllable. Then you can convert it to code easily. You also search for the Map section in the Java™ Tutorials, where there is an example about counting.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!