Ctrl K

Count the Tile Sequences

Medium
You have a set of letter tiles, like in a board game: the letters are given in the string tiles, one letter per tile. Letters may repeat. You lay one or more of the tiles in a row (using each tile at most once) and read off the sequence of letters. How many different non-empty letter sequences can you form? Rows that read the same are counted once, even if they use different tiles.
Example 1
tiles="XYY" → 8

Length 1: X, Y. Length 2: XY, YX, YY. Length 3: XYY, YXY, YYX. That is 8 in total.

Example 2
tiles="MN" → 4

You can make M, N, MN and NM.

Example 3
tiles="ZZZZ" → 4
Constraints
  • 1 ≤ len(tiles) ≤ 7
  • tiles consists of uppercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsKeypad Words MediumPalindromes From a Set of Letters MediumDoes the String Fit the Letter Template MediumA Hint for a Digit Guess MediumCharacters Grouped by Count Medium
loading Python…
Input
tiles="XYY"
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 39 tests on the server, hidden ones included.