This post is completed by 2 users

  • 0
Add to List
Hard

Print All The Permutations Of a String

Objective: Given a String, print all the permutations of it.

Input: A String

Output: Print all the permutations of a string

Example:

Input : abc
Output: abc acb bac bca cba cab

Approach:

  1. Take one character at a time and fix it at the first position. (use swap to put every character at the first position)
  2. make recursive call to rest of the characters.
  3. use swap to revert the string back to its original form fo next iteration.
Permutations

Code:


abc acb bac bca cba cab



Also Read: