FastPrepEdit Distance
Problems/Edit Distance

Edit Distance

Astrotalk logoAstrotalk● MediumFULLTIMENEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Astrotalk phone screen for full-time and new grad roles. The report names Edit Distance and asks for brute force. It leaves out which edits are allowed, their costs, the function signature, and the input limits. We chose those. Our version is about 85% the same as the reported question.

Given two case-sensitive strings source and target, return the minimum number of single-character operations needed to transform source into target.

One operation may insert a character, delete a character, or replace a character. Every operation costs 1.

Function

editDistance(source: String, target: String) → int

Examples

Example 1

source = "horse"target = "ros"return = 3

Replace h with r, delete the second r, and delete e.

Example 2

source = "sea"target = "eat"return = 2

Delete s and insert t at the end.

Example 3

source = ""target = "abc"return = 3

Insert all three target characters.

Constraints

  • 0 <= source.length, target.length <= 6
  • Both strings contain only English letters.
  • Character comparisons are case-sensitive.

Similar questions at other companies

  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Minimum Dictionary SegmentsGoogle · PHONE SCREENGoogle interview questions
  • Scramble StringExpedia · ONSITE INTERVIEWExpedia interview questions
  • Wildcard Pattern MatchingMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Every Result of Grouping an ExpressionC3.ai · ONSITE INTERVIEWC3.ai interview questions
  • Maximum Crayon Removal ScoreWells Fargo · OAWells Fargo interview questions
  • Shuffle a String by Swapping Tree ChildrenNutanix · OANutanix interview questions
  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
  • Longest Palindromic SubstringSiemens · PHONE SCREEN
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
See Astrotalk hiring insights
Saved
class Solution {
    public int editDistance(String source, String target) {
        // write your code here
    }
}
Checking account…