Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Tesla interview question

Minimum number of single-character edits to turn one string into another

Company:
Tesla
Round:
Phone screen
Type:
Coding
Difficulty:
Hard
Reported:
Q1 2026

Problem

Given two strings source and target, return the minimum number of operations needed to transform source into target. Three operations are allowed, and each costs 1:

  • insert a character at any position,
  • delete a character,
  • replace a character with a different character.

This minimum is also known as the Levenshtein distance between the two strings.

Example 1

Input: source = "kitten", target = "sitting"
Output: 3

Replace k with s, replace e with i, and insert g at the end.

Example 2

Input: source = "", target = "abc"
Output: 3

Three insertions are needed, and no shorter sequence exists.

Constraints

  • Either string may be empty; characters are compared exactly, so the comparison is case-sensitive.
  • The standard dynamic programming solution runs in O(m * n) time, where m and n are the string lengths.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern