Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Edit distance

    Edit distance

    Harddynamic programmingstring

    Return the fewest operations to turn word a into word b. Allowed: insert a character, delete one, or replace one. (Spell checkers use this to suggest nearby words.)

    Example 1

    Input:  a = "horse", b = "ros"
    Output: 3

    horse → rorse (replace) → rose (delete) → ros (delete).

    Example 2

    Input:  a = "intention", b = "execution"
    Output: 5

    Constraints

    • 0 ≤ a.length, b.length ≤ 500
    • Lowercase English letters

    Submit checks your solution against 8 tests, including hidden ones.

    /**
     * @param {string} a
     * @param {string} b
     * @return {int}
     */
    function minDistance(a, b) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.