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)
- Length of the smallest sub-string consisting of maximum distinct characters
- Find the number of strings formed using distinct characters of a given string
- 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
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Count number of substrings with exactly k distinct characters
- Count distinct substrings that contain some characters at most k times
- 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 email@example.com. 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.