Basic example
Input
'ab'
Output
['ab', 'ba']
Two characters have two permutations: 'ab' and 'ba'.
Full lesson preview
Return all unique permutations of the characters in a string, sorted lexicographically.
Problem statement
Task
Examples
Input
'ab'
Output
['ab', 'ba']
Two characters have two permutations: 'ab' and 'ba'.
Input
'aba'
Output
['aab', 'aba', 'baa']
Although there are 3! = 6 arrangements, duplicates collapse to 3 unique permutations sorted lexicographically.
Input format
Output format
Constraints
Samples
Input
'abc'
Output
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']
All permutations of a 3-character string.