Word Break with a Reusable Dictionary
Updated
Problem statement
Given a string s and a set of nonempty dictionary words, return whether s can be segmented into a sequence of one or more dictionary words.
Each dictionary word may be reused any number of times. The segmentation must cover the entire string in order. The empty string is segmentable using zero words.
Function
wordBreak(s: String, dictionary: List<String>) → booleanExamples
Example 1
s = "leetcode"dictionary = ["leet","code"]return = trueSplit the string as leet | code.
Example 2
s = "applepenapple"dictionary = ["apple","pen"]return = trueThe word apple is reused in apple | pen | apple.
Example 3
s = "catsandog"dictionary = ["cats","dog","sand","and","cat"]return = falseEvery possible prefix decomposition leaves a suffix that is not in the dictionary.
Constraints
0 <= s.length <= 5000.0 <= dictionary.length <= 5000.1 <= dictionary[i].length <= 100.sand every dictionary word contain only lowercase English letters.- Dictionary words are unique.
More Meta Onsite Interview questions
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
- Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
- Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
- Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
- Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
- Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word BreakMoveworks · ONSITE INTERVIEW
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
- Longest String ChainVisa · OA
- Minimum Dictionary SegmentsGoogle · PHONE SCREEN
- Count Equal-Frequency SubsequencesExpedia · OA
- Longest String ChainLinkedIn · OA
- Can the Text Split Into Dictionary WordsAdobe · PHONE SCREEN
- Longest Common URL History RunDatadog · PHONE SCREEN
- Word Break IIWex · PHONE SCREEN