Input : geeksforgeeks Output : eeeefggkkorss Input : coding Output : cdgino
sortString(str, n) Initialize new_str = "" for i = 'a' to 'z' for j = 0 to n-1 if str[j] == i, then new_str += str[j] return new_str
In the above method we have to traverse the entire string every time for each of the character in set of ‘a’ to ‘z’.We can overcome this drawback by maintaining a character and filling it with number of the occurrence’s of all the characters in the string.Later we can construct the required sorted string from the character array.
Below is the implementation.
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Map every character of one string to another such that all occurrences are mapped to the same character
- Replace every character of a string by a different character
- Sort the character array based on ASCII % N
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Find the character in first string that is present at minimum index in second string
- Convert the string into palindrome string by changing only one character.
- Queries to find the first non-repeating character in the sub-string of a string
- Queries to find the last non-repeating character in the sub-string of a given string
- Sort a string according to the order defined by another string
- How to Append a Character to a String in C
- Change string to a new character set
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Aravind_Alapati