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:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find all strings formed from characters mapped to digits of a number
- Find distinct characters in distinct substrings of a string
- Count the number of strings in an array whose distinct characters are less than equal to M
- Find the String having each substring with exactly K distinct characters
- Strings formed from given characters without any consecutive repeating characters
- Find all distinct palindromic sub-strings of a given string
- Count of distinct XORs formed by rearranging two Binary strings
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- String with k distinct characters and no same characters adjacent
- Replace minimal number of characters to make all characters pair wise distinct
- 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
- Count of times second string can be formed from the characters of first string
- Find total number of distinct years from a string
- Check whether second string can be formed from characters of first 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 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.