Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Word ladder

    Word ladder

    Hardgraphbfsstringhash set

    Turn begin into end by changing one letter per step, where every intermediate word must be in words. Return the number of words in the shortest chain (counting begin and end), or 0 if impossible. end must be in words.

    Example 1

    Input:  begin = "hit", end = "cog", words = ["hot","dot","dog","lot","log","cog"]
    Output: 5

    hit → hot → dot → dog → cog: 5 words.

    Example 2

    Input:  begin = "hit", end = "cog", words = ["hot","dot","dog","lot","log"]
    Output: 0

    Constraints

    • 1 ≤ begin.length ≤ 10
    • All words have the same length and are lowercase
    • 1 ≤ words.length ≤ 5000
    • begin ≠ end

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

    /**
     * @param {string} begin
     * @param {string} end
     * @param {string[]} words
     * @return {int}
     */
    function ladderLength(begin, end, words) {
      
    }
    
    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.