Word Break
Updated
Problem statement
Given a string s and an array of dictionary words wordDict, return true if s can be split into a sequence of one or more dictionary words. Otherwise, return false.
All words in wordDict are available for the entire call, and a word may be reused multiple times. Dictionary membership uses exact string equality; duplicate entries do not change the result.
Periodic-table dictionary variation
Use periodic-table entries in place of ordinary dictionary words and decide whether the input can be segmented entirely into the supplied entries. This is a vocabulary variation of the same boolean word-segmentation task, not a request to count or return every decomposition. Keep the supplied wordDict entries and exact string equality; do not assume a particular element list or silently change their case.
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.
Constraints
1 <= s.length <= 300.1 <= wordDict.length <= 1000.1 <= wordDict[i].length <= 20.- Every dictionary entry is non-empty.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Word BreakExpedia · ONSITE INTERVIEWExpedia 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