Problem · String
Generate All String Permutations
Learn this problemProblem statement
Given a string s whose characters are distinct lowercase English letters, return every permutation of its characters.
Return the permutations in lexicographic order.
Function
generatePermutations(s: String) → String[]Examples
Example 1
s = "abc"return = ["abc","acb","bac","bca","cab","cba"]All six arrangements of the three distinct characters are returned in lexicographic order.
Example 2
s = "ba"return = ["ab","ba"]The input order does not determine the output order; the two permutations are sorted lexicographically.
Example 3
s = "x"return = ["x"]A one-character string has exactly one permutation.
Constraints
1 <= s.length <= 8scontains distinct lowercase English letters.