MEDIUMasked at 26 companies

Edit Distance

A medium-tier problem at 59% community acceptance, tagged with String, Dynamic Programming. Reported in interviews at Nielsen and 25 others.

Founder's read

Edit Distance is the string problem that trips up candidates who haven't internalized dynamic programming yet. Asked by Nielsen, TikTok, Flipkart, and Swiggy among 26+ companies, it shows up regularly in medium-difficulty OA rounds. You get two strings and need to find the minimum number of edits (insert, delete, replace) to transform one into the other. The naive recursive approach explodes in time. The trick is building a DP table where each cell represents the cost to match prefixes. If you blank on the recurrence during the assessment, StealthCoder surfaces the solution invisible to the proctor.

Companies asking
26
Difficulty
MEDIUM
Acceptance
59%

Companies that ask "Edit Distance"

If this hits your live OA

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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The pattern here is classic DP but with a twist that catches people off guard. You're not finding a single optimal path; you're computing the cost matrix bottom-up. Start by creating a 2D table where dp[i][j] is the edit distance between the first i characters of string one and the first j characters of string two. Base cases: empty string to any string costs the string length. The recurrence branches: if characters match, copy the diagonal cost; if they don't, take the minimum of three neighbors (insert, delete, replace) and add 1. Common pitfall: forgetting the base cases or confusing row/column order. Space optimization (using a 1D array) is tempting but makes the code fragile. Time is O(m*n), space is O(m*n). StealthCoder is your safety net if the DP recurrence doesn't click mid-assessment.

Pattern tags

The honest play

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

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. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Edit Distance interview FAQ

How hard is Edit Distance really compared to other DP string problems?+

It's solidly medium and more accessible than some DP problems because the recurrence is mechanical once you see it. The acceptance rate sits near 59%, which reflects that most people who prepare DP at all can solve it. The trap is skipping DP and trying greedy or brute force under time pressure.

Is this still asked at tier-one companies?+

Yes. TikTok, Flipkart, and Nielsen have all reported it recently. It's not flashy, but it's a reliable gauge of whether you understand DP fundamentals and can code cleanly under stress. It's a filter problem, not a wow problem.

What's the key trick I'm missing if my solution is too slow?+

You're probably using pure recursion with overlapping subproblems and no memoization. The fix is the DP table. Build it iteratively from dp[0][0] upward. Each cell cost depends only on the three neighbors to its left, above, and diagonal. Fill left-to-right, top-to-bottom. No memoization overhead, just a straightforward O(m*n) loop.

How does Edit Distance relate to String and Dynamic Programming as topics?+

It's the canonical problem that proves DP works on strings. You're not sorting or searching; you're comparing character sequences and building up a cost table. Mastering this problem teaches you how to set up state, recurrence, and base cases for any string DP problem you'll face.

Should I optimize for space after I solve it correctly?+

Only if the interviewer pushes. The 2D table is clearer and easier to debug live. Space optimization to O(n) using a rolling array is smart in a take-home but risky under the clock. Get the DP recurrence right first. Speed and clarity matter more than squeezing memory during an OA.

Want the actual problem statement? View "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.