Permutations
Understand how to generate all possible permutations of a given string with unique lowercase characters. This lesson helps you practice arranging characters in every possible order, enhancing your approach to permutation problems often seen in coding interviews.
We'll cover the following...
Statement
Given an input string, word, return all possible permutations of the string.
Note: The order of permutations does not matter.
Constraints:
-
All characters in
wordare unique. -
word.length -
All characters in
wordare lowercase English letters.
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Permutations
What should be the output if the following string is given as input?
Input string = “xyz”
[“xyz”, “xzy”, “yxz”, “yzx”, “zyx”, “zxy”]
[“xyz”, “xzy”, “xxz”, “yzx”, “zyx”, “zxz”]
[“xyz”, “xzy”, “xxz”, “yzx”, “zyx”, “zxy”]
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in the following coding playground:
export function permuteWord(word){let result = [];// Replace this placeholder return statement with your codereturn result;}