Challenge: Find All Permutations of a String
Let’s practice our recursion skills and solve the first coding challenge of this course.
We'll cover the following
Let’s bring into practice our recursion skills and solve the first coding challenge of this course.
Problem statement
Given a string, str
, you are required to output an array containing all the possible permutations of that string. By permutation, we simply mean all the different arrangements of the characters of that string.
Input
Your input will be a single string str
.
str = "abc"
Output
Your function should return a list of all possible permutations of the string str
.
permutations(str) = ["abc", "acb", "bac", "bca", "cab", "cba"]
You should not change the prototype of function permutations
, as this will affect testing. You can make another function of the desired prototype and call it from permutations
.
Coding challenge
Carefully think about what the base case will be and how you will make recursive calls. You may look at hints if you feel stuck. Best of luck!
Get hands-on with 1400+ tech skills courses.