Word Break
Updated
Problem statement
Given a nonempty string s and a dictionary wordDict, return whether the entire string can be split into one or more dictionary words.
A dictionary word may be reused any number of times. Every character of the string must belong to exactly one chosen word, with no gaps or overlap.
Function
wordBreak(s: String, wordDict: List<String>) → booleanExamples
Example 1
s = "leetcode"wordDict = ["leet","code"]return = trueSplit s as leet + code. Both pieces belong to wordDict.
Example 2
s = "catsandog"wordDict = ["cats","dog","sand","and","cat"]return = falseThe prefixes cats and cat both lead to suffixes that cannot be fully segmented.
Example 3
s = "applepenapple"wordDict = ["apple","pen"]return = trueSplit s as apple + pen + apple. Reusing apple is allowed.
Example 4
s = "codingninjas"wordDict = ["coding","ninjas"]return = trueSplit the string as coding + ninjas. Both words are in the dictionary.
Constraints
1 <= s.length <= 300.1 <= wordDict.length <= 1000.1 <= wordDict[i].length <= 20.- The string and all dictionary words contain only lowercase English letters.
- Dictionary words are distinct.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Word BreakGoogle · ONSITE INTERVIEWGoogle interview questions
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
- Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Serialize and Deserialize an N-Ary TreeUber · ONSITE INTERVIEWUber interview questions
- Reconstruct One Sentence From a DictionaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
- Transitive Employee Referral CountsRobinhood · ONSITE INTERVIEWRobinhood interview questions