Detect Query Typos That Differ by Exactly One Letter

Last updated: November 29, 2026

Quick Overview

Build a dictionary of words; given a query, return True if changing exactly one character of the query produces a word in the dictionary.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Build a dictionary of words; given a query, return True if changing exactly one character of the query produces a word in the dictionary.

A Google technical screen question tied to Search spelling suggestions, where a typo that substitutes one letter should map to a known word. The interviewer checks a trie DFS with a single mismatch budget and the requirement that exactly one change be made.

What the Interviewer Expects
  • Insert words into a trie with end markers
  • Search with a remaining mismatch budget of one
  • Require that the budget is fully used at the end
  • Avoid accepting the exact word as a match
  • Compare with the wildcard-bucket hashing approach
Key Topics to Cover
trie
DFS
edit distance one
spell correction
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
  • How would you allow insertions and deletions as well?
  • How would you return all corrected words, ranked?
  • How would you scale this to edit distance 2?
  • What does the generalized-neighbor hash map look like?
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

build(words) stores distinct lowercase words. search(q) returns True iff some stored word has the same length as q and differs from it in exactly one position....

High-Level Design

Walk the trie and the query in lockstep with a budget used that is 0 or 1. At position i for a node, every child is a candidate: if the child's character equals q[i], move on with the same budge...


Submit Your Answer
Markdown supported