Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Print Permutations - String
EASY
30 mins
75 upvotes
Strings
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Strings
-
-
Other topics
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Print Permutations - String

Contributed by
Ashwani
Easy
yellow-spark
0/40
Avg time to solve 30 mins
Success Rate 80 %
Share
75 upvotes

Problem Statement

You are given an input string 'S'. Your task is to find and return all possible permutations of the input string.

Note:
1. The input string may contain the same characters, so there will also be the same permutations.

2. The order of permutation does not matter.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
cba
Sample Output 1:
abc
acb
bac
bca
cab
cba
Explanation for Sample Output 1:
All the possible permutations for string "cba" will be "abc", "acb", "bac", "bca", "cab" and "cba".
Sample Input 2:
xyx
Sample Output 2:
xyx
xxy
yxx
yxx
xyx
xxy
Explanation for Sample Output 2:
All the possible permutations for string "xyx" will be "xyx", "xxy", "yxx", "yxx", "xyx" and "xxy". Here, all three permutations "xyx", "yxx", "xxy" are repeating twice but we need to print all the possible permutations and hence we are printing them twice..
Reset Code
Full screen
Auto
copy-code
Console