Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Permutation of A String

Medium Acceptance 66.00% Points 30.00

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.

Hints
Hint 1
N/A
Constraints
  • 1 = length of string = 10
  • String contains only lowercase English letters
Companies
Amazon Microsoft Apple Samsung
Topics
String Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions