Suggest Spelling Corrections With a Symmetric Delete Index

Last updated: November 29, 2026

Quick Overview

Given a word-frequency dictionary, build an index that returns the top k correction candidates for a misspelled word within edit distance 2 (counting adjacent transpositions as one edit), ranked by distance and then by frequency.

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

0

0

0 solved


Given a word-frequency dictionary, build an index that returns the top k correction candidates for a misspelled word within edit distance 2 (counting adjacent transpositions as one edit), ranked by distance and then by frequency.

Spelling is the oldest Grammarly check and still has to answer within a few milliseconds per token for every open document. The interviewer is looking for a candidate who knows brute-force Levenshtein over the whole lexicon is too slow and can design a precomputed index, then verify candidates exactly.

What the Interviewer Expects
  • Explain why scanning the whole dictionary per query is too slow
  • Precompute delete variants for dictionary words so lookup is a few hash probes
  • Verify candidates with a true distance function, since shared deletes over-approximate
  • Handle transpositions (teh to the) as a single edit
  • Rank deterministically and discuss memory cost of the index
Key Topics to Cover
edit distance
symmetric delete
hashing
precomputation trade-off
ranking
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 big does the index get for a 500k word lexicon at distance 2, and how would you shrink it?
  • How would context (the surrounding sentence) change ranking between 'their' and 'there'?
  • How would you support a user's personal dictionary without rebuilding the index?
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

Dictionary maps word to corpus frequency. Query returns [word] if already correct, otherwise up to k candidates with OSA distance at most 2, sorted by (distance, -frequency, word)....

High-Level Design

Symmetric delete: if two strings are within distance d, some string reachable by at most d deletions from each is shared. At build time map every delete variant of each dictionary word to that word. A...


Submit Your Answer
Markdown supported

Related Questions