Talentd
FleetCode

1079. Letter Tile Possibilities

Medium83.5% acceptance5 companies

You have n  tiles, where each tile has one letter tiles[i] printed on it.

Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.

Example 1:

Input: tiles = "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".

Example 2:

Input: tiles = "AAABBC"
Output: 188

Example 3:

Input: tiles = "V"
Output: 1

Constraints:

  • 1 <= tiles.length <= 7
  • tiles consists of uppercase English letters.

Hints open one at a time

Hint 1
Try to build the string with a backtracking DFS by considering what you can put in every position.
13:28
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def numTilePossibilities(self, tiles: str) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
"AAB"
Input
"AAABBC"
Input
"V"
Your code is saved on this device.Solution