Jump to content
xisto Community
varalu

Data Structures -- String -- Arrange Based On Repetition String data structure

Recommended Posts

Consider a string with any number of elements occurring any number of time.

 

Rearrange the string in such a way that the alphabet with most occurrence occurs in the followed by the next most occurring alphabet and so on... It should also be seen that the alphabets should occur frequency number of times.

 

Example:

 

Input : abcdaeghzabcdbhb

Output : bbbbaaaccddhhegz

Share this post


Link to post
Share on other sites

First of all, why are you posting a problem and not a solution or tutorial on how to find the solution? Your current post is just stupid since it is hard to respond to and it just looks like you are trying to get credits in any possible way.However, to solve this (since you did not say) is really easy. You can do it in O(n) and there are multiple ways to achieve this. The easiest method is O(n^2) or O(nlogn) depending on the sort method used. Since you know the size of the alphabet so you can initilize counts to zero. Then go through the string incrementing the letter's value by 1. Then just sort the list and print out the corresponding letter's and their counts. To do this in O(n), you would have to be kinda of tricky with how you store and sort. What you would do is obtain a letter's value and concatenate that number of them to the correct part of the out string (which you would keep track of with another string of values or an array).

Share this post


Link to post
Share on other sites
Rearrange the string in such a way that the alphabet with most occurrence occurs in the followed by the next most occurring alphabet and so on... It should also be seen that the alphabets should occur frequency number of times.Data Structures -- String -- Arrange Based On Repetition

Rearrange the string in such a way that the alphabet with most occurrence occurs in the followed by the next most occurring alphabet and so on... It should also be seen that the alphabets should occur frequency number of times.

-question by Abram

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.