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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Check if any permutation of string is a K times repeated string
- 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 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 number of given operations required to convert a string to another string
- Split the string into minimum parts such that each part is in the another string
- Minimum changes required to make first string substring of second string
- Convert string X to an anagram of string Y with minimum replacements
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
- Lexicographically n-th permutation of a string
- String which when repeated exactly K times gives a permutation of S
- Print all permutation of a string using ArrayList
- Find n-th lexicographically permutation of a string | Set 2
- Number of distinct permutation a String can have
- 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 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.