All Permutations II
Given a string with possible duplicate characters, return a list with all permutations of the characters.
Examples
Set = “abc”, all permutations are [“abc”, “acb”, “bac”, “bca”, “cab”, “cba”]
Set = "aba", all permutations are ["aab", "aba", "baa"]
Set = "", all permutations are [""]
Set = null, all permutations are []
Solution: Recursive DFS with Hashset
Time Comp: O(N) Hashset * O(N!) branches = O(N^2)
Space Comp: O(N) Hashset
Last updated
Was this helpful?