Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Permutation of A String

Medium Acceptance 66% Points 30

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.

Examples
Example 1

Example 1

Input: s = "a"

Output: a

Explanation: Only one arrangement is possible.

Example 2

Example 2

Input: s = "ab"

Output: ab ba

Explanation: The two characters can be arranged in two different ways.

Example 3

Example 3

Input: s = "abc"

Output: abc acb bac bca cab cba

Explanation: All possible orderings of the three characters are generated.

Constraints
  • 1 = length of string = 10
  • String contains only lowercase English letters
Topics
String Recursion
Companies
Amazon Microsoft Apple Samsung
Added 19 Jul 2026 66% acceptance
Ln 1, Col 1Sign in to save your code
abc
abc acb bac bca cab cba