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:
- Find distinct characters in distinct substrings of a string
- 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)
- Contiguous subsegments of a string having distinct subsequent characters
- Find the number of strings formed using distinct characters of a given string
- 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
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Count number of substrings with exactly k distinct characters
- Minimum length substring with exactly K distinct characters
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.