Letter Tile Possibilities - Problem
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.
Note: You may use each tile at most once per sequence.
Input & Output
Example 1 — Basic Case
$
Input:
tiles = "AAB"
›
Output:
8
💡 Note:
Possible sequences: "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA". Total of 8 sequences.
Example 2 — All Same Characters
$
Input:
tiles = "AAABBC"
›
Output:
188
💡 Note:
With frequencies A:3, B:2, C:1, we can form many sequences of lengths 1-6. Each length has unique permutations based on character frequencies.
Example 3 — Single Character
$
Input:
tiles = "V"
›
Output:
1
💡 Note:
Only one sequence possible: "V"
Constraints
- 1 ≤ tiles.length ≤ 7
- tiles consists of uppercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input Tiles
Given string of letter tiles like 'AAB'
2
Generate Sequences
Form all possible non-empty sequences using each tile at most once
3
Count Unique
Return total number of unique sequences
Key Takeaway
🎯 Key Insight: Use backtracking with frequency counting to systematically generate all possible sequences without duplicates
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code