Given a string str that may contain duplicate characters, the task is to print all the distinct permutations of the given string such that no permutation is repeated in the output.
Input: str = “ABA”
Input: str = “ABC”
Approach: An approach to generate all the permutations of a given string has been discussed in this article. All the permutations generated by this approach can be stored in a HashSet in order to avoid duplicates.
Below is the implementation of the above approach:
ABA AAB BAA
- Print all distinct permutations of a given string with duplicates
- Print distinct sorted permutations with duplicates allowed in input
- Java Program to print distinct permutations of a string
- Distinct permutations of the string | Set 2
- Iterative program to generate distinct Permutations of a String
- Print all permutations of a string in Java
- Find distinct characters in distinct substrings of a string
- Find Kth largest string from the permutations of the string with two characters
- Permutations of a given string using STL
- All permutations of a string using iteration
- Time complexity of all permutations of a string
- Print all palindrome permutations of a string
- Write a program to print all permutations of a given string
- Generate all permutations of a string that follow given constraints
- Check if a binary string contains all permutations of length k
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.