Solution: Letter Tile Possibilities
Let’s solve the Letter Tile Possibilities problem using the Subsets pattern.
We'll cover the following
Statement
You are given a string, tiles
, consisting of uppercase English letters. You can arrange the tiles into sequences of any length (from 1 to the length of tiles
), and each sequence must include at most one tile, tiles[i]
, from tiles
.
Your task is to return the number of possible non-empty unique sequences you can make using the letters represented on tiles[i]
.
Constraints:
tiles.length
The
tiles
string consists of uppercase English letters.
Solution
This problem would have been straightforward if the tiles
had no duplicates and we only needed to find sequences of the same length as the given tiles
. In that case, we could simply calculate the total unique sequences using tiles
).
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.