Decode Multi-Tap Phone Keypad Presses Separated by Pauses
Last updated: November 29, 2026
Quick Overview
On an old phone keypad, pressing a digit key repeatedly cycles through its letters (2 is abc, 7 is pqrs, 0 is a space). Given a string of key presses where a space means a pause that commits the current letter, decode the typed message.
0
0
0 solved
On an old phone keypad, pressing a digit key repeatedly cycles through its letters (2 is abc, 7 is pqrs, 0 is a space). Given a string of key presses where a space means a pause that commits the current letter, decode the typed message.
An online assessment style problem for Google that is really a small state machine: the current key and its press count. It tests careful commit logic at key changes, pauses, and the end of input, which is where most candidates drop characters.
What the Interviewer Expects
- Model state as (current key, press count)
- Commit a letter when the key changes, on a pause, and at the end
- Wrap around with modulo when presses exceed the letter count
- Handle the 0 key as a space
- Keep the code free of off-by-one errors
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add a long-press that types the digit itself?
- How would you support T9 predictive input with a dictionary instead?
- What if the input includes a backspace key?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a string over digits 0 and 2-9 plus the space character as a pause. Output: the decoded text. Same key pressed consecutively without a pause cycles letters, wrapping around. A different key...
High-Level Design
Hold key and count. A helper flush() appends letters[key][(count-1) % len] if a key is pending, then clears state. For each character: if it is a pause, flush. If it equals the pending key, in...