You are given a string. Your task is to generate all possible permutations of the characters. A permutation is formed by rearranging the characters in every possible order. Return all permutations of the string.
Example 1
Input: s = "a"
Output: a
Explanation: Only one arrangement is possible.
Example 2
Input: s = "ab"
Output: ab ba
Explanation: The two characters can be arranged in two different ways.
Example 3
Input: s = "abc"
Output: abc acb bac bca cab cba
Explanation: All possible orderings of the three characters are generated.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
abc
abc acb bac bca cab cba
ab
ab ba