Given a string str consisting of lowercase English alphabets, the task is to find the count of all possible string of maximum length that can be formed using the characters of str such that no two characters in the generated string are same.
Input: str = “aba”
“ab” and “ba” are the only valid strings.
Input: str = “geeksforgeeks”
Approach: First, count the number of distinct characters in the string say cnt as no two characters can be same in the resultant string. Now, the total number of strings that can be formed with cnt number of characters is cnt! as every character of str has to be present in the generated string in order to maximise the length and no character should appear more than once.
Below is the implementation of the above approach:
- Find all strings formed from characters mapped to digits of a number
- Find distinct characters in distinct substrings of a string
- Find all distinct palindromic sub-strings of a given string
- String with k distinct characters and no same characters adjacent
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Replace minimal number of characters to make all characters pair wise distinct
- Check whether second string can be formed from characters of first string
- Find total number of distinct years from a string
- Lexicographically largest string formed from the characters in range L and R
- All possible strings of any length that can be formed from a given string
- Convert given string so that it holds only distinct characters
- Check if given string can be formed by two other strings or their permutations
- Count of strings that can be formed from another string using each character at-most once
- Print all distinct characters of a string in order (3 Methods)
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.