Given a string str consisting of lowercase English alphabets, the task is to convert the string so that it holds only distinct characters. Any character of the string can be replaced by any other lowercase character (the number of replacements must be minimum). Print the modified string.
Input: str = “geeksforgeeks”
Input: str = “bbcaacgkkk”
Approach: If the length of the string > 26 then it won’t be possible for the string to have all distinct characters.
Else, count the occurrence for each of the character of the string and for the characters that appear more than once, replace them with some character that hasn’t appeared in the string yet. Print the modified string in the end.
Below is the implementation of the above approach:
- String with k distinct characters and no same characters adjacent
- Check whether count of distinct characters in a string is Prime or not
- Print all distinct characters of a string in order (3 Methods)
- Length of the smallest sub-string consisting of maximum distinct characters
- Python | Convert a list of characters into a string
- Convert characters of a string to opposite case
- Convert a String into a square matrix grid of characters
- Replace minimal number of characters to make all characters pair wise distinct
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Count distinct substrings that contain some characters at most k times
- Minimum length substring with exactly K distinct characters
- Count number of substrings with exactly k distinct characters
- Min flips of continuous characters to make all characters same in a string
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
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.