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.

Google
Coding & Algorithms
Frontend Engineer
Google
November 29, 2026
Frontend Engineer
Phone Screen
Coding & Algorithms
Easy

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
Two Pointers
Strings
Greedy
Subsequence
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: strings typed and suggestion.
  • Output: True if typed can be formed by deleting zero or more characters from suggestion without 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...


Submit Your Answer
Markdown supported