← Practice problem bank

Dec 31, 2025

Combinatorial Wordsmith

Daily Challenge Archive · Open

easysorting

100 pts · 10000 ms · 128 MB · Practice only

Problem

Imagine you are a visionary linguist tasked with crafting an entirely new language. Your mission is to take a string of distinct lowercase letters and discover every possible way these letters can be arranged to form new 'words'. Each permutation represents a potential word in this budding language, and your goal is to list them all in alphabetical order, showcasing the myriad possibilities. Here's how to tackle this challenge step-by-step: 1. Read the input string, which will be composed of unique lowercase letters. 2. Generate all permutations of these letters. 3. Sort these permutations in lexicographical order, akin to a dictionary's alphabetical arrangement. 4. Output each permutation on a new line. For example, given the string 'abc', your output should be: 'abc', 'acb', 'bac', 'bca', 'cab', 'cba'. Consider edge cases like the smallest input, such as a single letter, or larger strings with more complex arrangements.

Hints
Consider using recursive backtracking or a library function to generate permutations efficiently. Sorting the results will ensure they are in the desired order. Watch out for cases where the input size increases, and think about the computational implications. Remember, practice makes perfect, and this exercise will deepen your understanding of permutations in mathematics and computer science!

Input format

A single string of distinct lowercase letters (1 <= length <= 6).

Output format

All unique permutations of the input string, each on a new line, in lexicographical order.

Constraints

The input string will only contain distinct lowercase letters.

Sample input

abc

Sample output

abc
acb
bac
bca
cab
cba

Sign in to submit solutions

Run your code against all test cases and get instant feedback.

Sign in