MEDIUMasked at 3 companies

One Edit Distance

A medium-tier problem at 34% community acceptance, tagged with Two Pointers, String. Reported in interviews at X and 2 others.

Founder's read

One Edit Distance comes up at X, Snap, and Yandex, and only a third of candidates pass it. The problem looks straightforward until you realize the naive two-pointer walk fails on edge cases. You need to identify which single edit (insert, delete, or replace) transforms one string into another, and the trick is recognizing when to advance pointers differently based on string lengths. If you blank on the pattern during the live assessment, StealthCoder detects the problem in seconds and surfaces the working solution invisible to the proctor.

Companies asking
3
Difficulty
MEDIUM
Acceptance
34%

Companies that ask "One Edit Distance"

If this hits your live OA

One Edit Distance is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The algorithm hinges on two pointers moving through both strings, but the movement isn't symmetric. If the strings differ by exactly one character in length, you can't just compare character-by-character and advance both pointers in lockstep. When characters match, advance both pointers. When they don't, you have three cases: replace (advance both), delete from the longer string (advance only that pointer), or insert into the longer string (same as delete, algorithmically). The catch is handling the length difference upfront and recognizing that once you've made one edit, any further mismatch means the strings aren't one edit apart. Most candidates miss the asymmetric pointer logic or fail to early-exit when a second edit becomes necessary. StealthCoder is your hedge for the one-off edge case that tanks your submission.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

One Edit Distance recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

One Edit Distance interview FAQ

What makes One Edit Distance harder than it looks?+

The problem is deceptively simple. Basic two-pointer iteration breaks on length mismatches. You must handle three edit types separately (replace, insert, delete) and track whether you've already made one edit. One extra mismatch after that means false. The length difference itself encodes which edit to try first.

Is this problem actually asked at big companies?+

Yes. X, Snap, and Yandex report asking it. The 34% acceptance rate suggests it's a medium-difficulty filter, not a gimme. Companies use it to test pattern recognition and edge-case handling, not heavy algorithms.

What's the difference between this and LCS or edit distance DP?+

Classic edit distance (Levenshtein) counts minimum edits via DP and allows unlimited operations. One Edit Distance is a binary check: exactly zero or one edit transforms string A to B. The constraint is tighter, so pointer-based approaches work. DP is overkill and slower.

How do I avoid the off-by-one or double-edit trap?+

After you detect a mismatch, make exactly one edit (replace, insert, or delete based on lengths) and then check if the rest of the strings match exactly. If they don't, return false immediately. Don't count a second mismatch. The two-pointer approach forces you to be explicit about this boundary.

Should I use two pointers or just string slicing?+

Two pointers is the canonical O(1) space solution. Slicing (taking substrings after the mismatch) is cleaner to code and still O(n) time, acceptable for interviews. Two pointers impresses, but clarity beats golf in live assessments. Pick what you can code without bugs in three minutes.

Want the actual problem statement? View "One Edit Distance" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.