Search⌘ K
AI Features

Permutations

Explore how to generate all possible permutations of a string with unique lowercase characters. Understand the problem constraints and develop a solution that rearranges characters effectively. This lesson helps you apply permutation concepts crucial for coding interviews.

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 word are unique.

  • 11 \leq word.length 6\leq 6

  • All characters in word are 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

1.

What should be the output if the following string is given as input?

Input string = “xyz”

A.

[“xyz”, “xzy”, “yxz”, “yzx”, “zyx”, “zxy”]

B.

[“xyz”, “xzy”, “xxz”, “yzx”, “zyx”, “zxz”]

C.

[“xyz”, “xzy”, “xxz”, “yzx”, “zyx”, “zxy”]


1 / 3

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.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5

Try it yourself

Implement your solution in the following coding playground:

Java
usercode > Main.java
import java.util.*;
public class Main{
public static ArrayList<String> permuteWord(String word) {
// Replace this placeholder return statement with your code
return new ArrayList<>();
}
}
Permutations