All Permutation String
Input abc -> abc, acb, bac, bca, cba, cab
Solution: "swap swap"
Base Case: if (index == input.length) return
Recursive Rule:
branch N - Index times
swap index and i
call self on next index
swap index and i, undo swap
Implementation:
Time Comp: O(N!) or O(N! * N) if adding String to result[]
Space Comp: O(N levels)
Last updated
Was this helpful?