Edit Distance
Updated
Problem statement
Given two strings word1 and word2, return the minimum number of operations needed to transform word1 into word2.
One operation may insert one character, delete one character, or replace one character.
Function
minDistance(word1: String, word2: String) → intExamples
Example 1
word1 = "horse"word2 = "ros"return = 3Replace h with r, delete the second r, and delete e.
Example 2
word1 = "intention"word2 = "execution"return = 5Five insert, delete, or replace operations are sufficient and optimal.
Example 3
word1 = ""word2 = "abc"return = 3Insert the three characters of the target.
Constraints
0 <= word1.length, word2.length <= 500.- Both strings contain only lowercase English letters.
More Bloomberg LP Onsite Interview questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Minimum Insertion Steps to Make a String PalindromeInfosys · ONSITE INTERVIEWInfosys interview questions
- Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
- Concatenated WordsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Interleaving StringsCARS24 · ONSITE INTERVIEW
- Minimum Stickers to Form a Target StringByteDance · ONSITE INTERVIEWByteDance interview questions
- Longest Valid ParenthesesMathWorks · ONSITE INTERVIEWMathWorks interview questions
- Word Break II: All SentencesMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Longest Valid ParenthesesMaven Clinic · ONSITE INTERVIEWMaven Clinic interview questions
- Word Break IIGoogle · ONSITE INTERVIEWGoogle interview questions
- Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions