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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Strings formed from given characters without any consecutive repeating characters
- Find distinct characters in distinct substrings of a string
- Find all strings formed from characters mapped to digits of a number
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- String with k distinct characters and no same characters adjacent
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Count of distinct XORs formed by rearranging two Binary strings
- Check if a given string can be formed using characters of adjacent cells of a Matrix
- Count of Distinct strings possible by inserting K characters in the original string
- Replace minimal number of characters to make all characters pair wise distinct
- Longest palindromic String formed using concatenation of given strings in any order
- Print all possible palindromic string formed using any pair of given strings
- Count the number of strings in an array whose distinct characters are less than equal to M
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Count of times second string can be formed from the characters of first string
- Check whether second string can be formed from characters of first string
- Distinct strings such that they contains given strings as sub-sequences
- Total length of string from given Array of strings composed using given characters
- Find all distinct palindromic sub-strings of a given string
- Distinct palindromic sub-strings of the given string using Dynamic Programming
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.