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

    Word break

    Mediumdynamic programmingstringhash set

    Return true if s can be split into words that are all in the dictionary words. A word may be reused.

    Example 1

    Input:  s = "seacode", words = ["sea","code"]
    Output: true

    Example 2

    Input:  s = "applepenapple", words = ["apple","pen"]
    Output: true

    Example 3

    Input:  s = "catsandog", words = ["cats","dog","sand","and","cat"]
    Output: false

    Constraints

    • 1 ≤ s.length ≤ 300
    • 1 ≤ words.length ≤ 1000

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

    /**
     * @param {string} s
     * @param {string[]} words
     * @return {bool}
     */
    function wordBreak(s, 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.