Letter Combinations of a Phone Number
Given a string containing digits 2-9, return all possible letter combinations Mapping: 2->abc, 3->def, 4->ghi, 5->jkl, 6->mno, 7->pqrs, 8->tuv, 9->wxyz Example: digits = "23" => ["ad","ae","af","bd","be","bf","cd","ce","cf"]
This one is about exploring choices without getting lost—choose, recurse, undo, repeat. Interviewers love it because it reveals your structured exploration and your edge-case discipline. If you can explain your pruning, this stops feeling like brute force.
Examples
You write
letter_combinations(digits: str)
Example 1
- Input
- digits = "23"
- returns
- ["ad","ae","af","bd","be","bf","cd","ce","cf"]
Example 2
- Input
- digits = "2"
- returns
- ["a","b","c"]
The pattern behind it
Arrays & Hashing
I reach for it when
- You catch yourself scanning the array again for every element.
- The problem asks about duplicates, pairs, counts or groups.
Say this before you type. Say what the key is and what the value remembers, before you write the loop.
All 127 Arrays & Hashing problemsStrings
I reach for it when
- The input is text and the answer is a count, a substring or a new string.
- You need to compare, reverse or rebuild characters.
Say this before you type. Say which array pattern the string is hiding before you touch a character.
All 51 Strings problems
Meet Coco
Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.