Easy · Backtracking

All Length-K Strings from a Character Set

Given a string chars of distinct characters and an integer k, return every string of length k made from those characters, with repetition allowed, in any order.

Examples

Example 1

"ab", k=2

Output: 4 strings

Example 2

"abc", k=2

Output: 9 strings

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Backtracking problems