This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

maximum occurences of a character  RSS feed

 
pravanya Gullapudi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have given a string. i need to find out maximum occurences of a letter in that string. If two letters have same count, then you choose one which is first in alphabetical order...


example gullapudi l=2,u=2 so you choose l as result...


i need the code for this...

any one can help me
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you written so far? What are you stuck on?
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try creating a hash where the letter is the key and the value is the number of occurrences, then you can get a char array from the original string. At the end you can get a set from the hash and order it first by number of occurrences and then the alphabetical order.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!