Is a Typed Query a Subsequence of an Autocomplete Suggestion
Last updated: November 29, 2026
Quick Overview
Given what a user has typed and a candidate autocomplete suggestion, return whether the typed characters appear in the suggestion in order, not necessarily contiguously.
0
0
0 solved
Given what a user has typed and a candidate autocomplete suggestion, return whether the typed characters appear in the suggestion in order, not necessarily contiguously.
A Google-style fuzzy matching warm-up tied to search box suggestions, where a user typing `gml` should still match `gmail`. The interviewer checks the greedy two-pointer scan and then pushes into the follow-up of matching against many suggestions quickly.
What the Interviewer Expects
- Uses one pointer per string and a single pass
- Explains why greedy matching of the earliest character is safe
- Returns early when the typed string is fully matched
- Handles empty typed input
- Discusses preprocessing for many queries against one suggestion
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
- If you check millions of typed strings against the same long suggestion, how would you preprocess it?
- How would you rank suggestions by how tightly the characters match?
- How would you make the match case-insensitive and accent-insensitive?
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: strings
typedandsuggestion. - Output: True if
typedcan be formed by deleting zero or more characters fromsuggestionwithout reordering. - Exact character comparison for the base p...
High-Level Design
Walk through suggestion with pointer j while pointer i marks how much of typed has been matched. Whenever suggestion[j] == typed[i], advance i. If i reaches the end of typed, every cha...