Given a string where, . Assume that all the characters in are unique. The task is to compute the minimum length of a string which consists of all the permutations of the given string in any order.
Note: All permutations must be present as a substring in the resulting string.
Input : ab Output : 3 The resulting string is aba. Input : abc Output : 9 The resulting string is abcabacba.
Approach: The answer to the above problem is simple.
- If the length of string is 1, then answer is 1.
- If the length of string is 2, then answer is 3.
- If the length of string is 3, then answer is 9.
So, after observing the output we can see that if the length of the string is n, then answer will be 1! + 2! + … + n!. Hence we can precompute the result upto n = 26 in vector of strings.
Below is the implementation of above approach.
- Maximum even length sub-string that is permutation of a palindrome
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Reduce the string to minimum length with the given operation
- Minimum length String with Sum of the alphabetical values of the characters equal to N
- Find length of longest subsequence of one string which is substring of another string
- Check if a string contains a palindromic sub-string of even length
- Minimum number of given operations required to convert a string to another string
- Minimum deletions from string to reduce it to string with at most 2 unique characters
- Find the character in first string that is present at minimum index in second string
- Minimum changes required to make first string substring of second string
- Convert string X to an anagram of string Y with minimum replacements
- Lexicographically n-th permutation of a string
- Number of distinct permutation a String can have
- String which when repeated exactly K times gives a permutation of S
- Print all permutation of a string using ArrayList
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.