`{"id":"1799f2f9-d8ee-4e5d-b07a-ffbe9783d460","name":"Print Permutations","description":"1. You are given a string str.\r\n2. Complete the body of printPermutations function - without changing signature - to calculate and print all permutations of str.\r\nUse sample input and output to take idea about permutations.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A string str","outputFormat":"Permutations of str in order hinted by Sample output","constraints":"0 &lt;= str.length &lt;= 7","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nvoid printPermutations(string str, string asf){\r\n // write your code here\r\n\r\n}\r\n\r\nint main(){\r\n string str;\r\n cin>>str;\r\n printPermutations(str,\"\");\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n public static void printPermutations(String str, String asf) {\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printPermutation(ques , asf):\r\n # Write your code here\r\n\r\nif __name__ \"\" '__main__':\r\n s = input().strip()\r\n printPermutation(s , \"\");"}},"points":10,"difficulty":"easy","sampleInput":"abc","sampleOutput":"abc\r\nacb\r\nbac\r\nbca\r\ncab\r\ncba","questionVideo":"https://www.youtube.com/embed/K5xJXbnYMBc","hints":[],"associated":[{"id":"13e5ce81-2498-4487-a952-11ad2f2eaf66","name":"(Print Permutations) What is the space complexity for this problem ?","slug":"print-permutations-what-is-the-space-complexity-for-this-problem","type":4},{"id":"2edaa2b4-dba1-4013-8bef-a1c73d4d58bb","name":"(Print Permutations) When should the recursion stop ?","slug":"print-permutations-when-should-the-recursion-stop","type":4},{"id":"497b9b45-3585-42a1-a91a-5acae9810424","name":"(Print Permutations) What should be the substring to pass in the recursive call if we choose i'th character from the string ?","slug":"print-permutations-what-should-be-the-substring-to-pass-in-the-recursive-call-if-we-choose-i-th-character-from-the-string","type":4},{"id":"9e1ee7aa-e25f-4f8f-9e1b-b4504a6dcfd5","name":"(Print Permutations) What is the time complexity for this problem ?","slug":"print-permutations-what-is-the-time-complexity-for-this-problem","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"f86d36fe-a690-45b9-bf3f-632b9a84a2af","name":"Print Permutations","slug":"print-permutations","type":1}],"next":{"id":"a1dc5243-d15c-4cf2-b512-13dfcdfa92ae","name":"Print Permutations","type":3,"slug":"print-permutations"},"prev":{"id":"accafbbd-0580-4dfd-9f27-b0b13627c558","name":"Print Maze Path With Jumps","type":3,"slug":"print-maze-path-with-jumps"}}}`

# Print Permutations

1. You are given a string str. 2. Complete the body of printPermutations function - without changing signature - to calculate and print all permutations of str. Use sample input and output to take idea about permutations. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

`{"id":"1799f2f9-d8ee-4e5d-b07a-ffbe9783d460","name":"Print Permutations","description":"1. You are given a string str.\r\n2. Complete the body of printPermutations function - without changing signature - to calculate and print all permutations of str.\r\nUse sample input and output to take idea about permutations.\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A string str","outputFormat":"Permutations of str in order hinted by Sample output","constraints":"0 &lt;= str.length &lt;= 7","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nvoid printPermutations(string str, string asf){\r\n // write your code here\r\n\r\n}\r\n\r\nint main(){\r\n string str;\r\n cin>>str;\r\n printPermutations(str,\"\");\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n public static void printPermutations(String str, String asf) {\r\n \r\n }\r\n\r\n}"},"python":{"code":"def printPermutation(ques , asf):\r\n # Write your code here\r\n\r\nif __name__ \"\" '__main__':\r\n s = input().strip()\r\n printPermutation(s , \"\");"}},"points":10,"difficulty":"easy","sampleInput":"abc","sampleOutput":"abc\r\nacb\r\nbac\r\nbca\r\ncab\r\ncba","questionVideo":"https://www.youtube.com/embed/K5xJXbnYMBc","hints":[],"associated":[{"id":"13e5ce81-2498-4487-a952-11ad2f2eaf66","name":"(Print Permutations) What is the space complexity for this problem ?","slug":"print-permutations-what-is-the-space-complexity-for-this-problem","type":4},{"id":"2edaa2b4-dba1-4013-8bef-a1c73d4d58bb","name":"(Print Permutations) When should the recursion stop ?","slug":"print-permutations-when-should-the-recursion-stop","type":4},{"id":"497b9b45-3585-42a1-a91a-5acae9810424","name":"(Print Permutations) What should be the substring to pass in the recursive call if we choose i'th character from the string ?","slug":"print-permutations-what-should-be-the-substring-to-pass-in-the-recursive-call-if-we-choose-i-th-character-from-the-string","type":4},{"id":"9e1ee7aa-e25f-4f8f-9e1b-b4504a6dcfd5","name":"(Print Permutations) What is the time complexity for this problem ?","slug":"print-permutations-what-is-the-time-complexity-for-this-problem","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"f86d36fe-a690-45b9-bf3f-632b9a84a2af","name":"Print Permutations","slug":"print-permutations","type":1}],"next":{"id":"a1dc5243-d15c-4cf2-b512-13dfcdfa92ae","name":"Print Permutations","type":3,"slug":"print-permutations"},"prev":{"id":"accafbbd-0580-4dfd-9f27-b0b13627c558","name":"Print Maze Path With Jumps","type":3,"slug":"print-maze-path-with-jumps"}}}`

Editor

# Print Permutations

easy

1. You are given a string str. 2. Complete the body of printPermutations function - without changing signature - to calculate and print all permutations of str. Use sample input and output to take idea about permutations. Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

## Constraints

0 <= str.length <= 7

## Format

A string str

### Output

Permutations of str in order hinted by Sample output

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}abc`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}abc acb bac bca cab cba```

Question Video

Discussions

Show Discussion

Related Resources