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
- 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 deletions from string to reduce it to string with at most 2 unique characters
- Minimum number of given operations required to convert a string to another string
- Find the character in first string that is present at minimum index in second string
- Covert string X to an anagram of string Y with minimum replacements
- Minimum changes required to make first string substring of second string
- Lexicographically n-th permutation of a string
- Find n-th lexicographically permutation of a string | Set 2
- Number of distinct permutation a String can have
- Print all permutation of a string using ArrayList
- String which when repeated exactly K times gives a permutation of S
- Lexicographically smallest permutation of a string with given subsequences
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.