This post is completed by 6 users

  • 0
Add to List
Hard

58. Generate All String Permutations

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

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

 
abc acb bac bca cba cab