Predictive T9 Suggestions From a Partial Keypad Sequence
Last updated: November 29, 2026
Quick Overview
Given a dictionary of words with frequencies and a sequence of phone keypad digits typed so far, return the top three words whose keypad encoding starts with that digit sequence, ranked by frequency.
0
0
0 solved
Given a dictionary of words with frequencies and a sequence of phone keypad digits typed so far, return the top three words whose keypad encoding starts with that digit sequence, ranked by frequency.
A Google technical screen question framed around predictive text on a feature phone keyboard, still relevant for Gboard on low-end Android devices. It checks building a trie over digit encodings instead of letters and caching top results per node.
What the Interviewer Expects
- Map each word to its keypad digit string
- Insert into a trie over digits
- Cache the top three words by frequency at each node
- Answer by walking the typed digits
- Explain why a letter trie would need exponential branching
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 support updating frequencies as the user picks words?
- How would you blend a personal dictionary with a global one?
- What if digit 1 is punctuation and 0 is space?
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: freq, a dict of lowercase word to count, and digits, a string over 2-9. Output: up to three words, highest count first and alphabetical on ties, whose keypad encoding starts with digits...
High-Level Design
A letter trie would force us to try 3 or 4 letters for each digit, giving exponential branching. Instead, convert each word to digits once (home becomes 4663) and insert that digit string into a t...