How can I echo characters before and after a string?

We have a string of characters and we want to find characters with second highest frequency in the string. Suggest different algorithms for this?

  • e.g.  string =  abaabc output = b  (since a is appearing 3 times which is highest and b is appearing 2 times which is 2nd highest) e.g string = ababcacad output = b,c need algorithm/logic which is easy to implement for beginner. I don 't want to use hash or other kind of data structure. and so we are not concerned about space/time complexity . looking for simple array/iterative algorithm. My approach: step1 : make a structure with two member (char and int)=(character and frequency) step2: sort structure by frequency in descending order(and of-course sort corresponding characters ). step3: start printing from second index of structure if the frequency of this is not equal to 1st's frequency. ...... and so on .

  • Answer:

    Make a hash function and store the frequency of alphabets in a hash table[26] ; then just go through the table to find the second highest !!

Mukul Dilwaria at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.