Can the Text Split Into Dictionary Words
Updated
Problem statement
You are given a string s and a list of words wordDict. Return true if s can be cut into pieces so that every piece is a word from wordDict, and false otherwise.
The pieces must cover s exactly, in order, with no letters left over and no overlap. A word may be used any number of times, and some words may not be used at all.
Function
canSplit(s: String, wordDict: String[]) → booleanExamples
Example 1
s = "redredwood"wordDict = ["red","wood","redw"]return = trueSplit it as red + red + wood. The same word may be used more than once, so the answer is true.
Example 2
s = "pinetrees"wordDict = ["pin","pine","etree","tree"]return = falsepine + tree leaves s, and pin + etree also leaves s. No word is s or ends with it, so no split works: false.
Example 3
s = "sunflowerpot"wordDict = ["sunflow","sun","flower","pot"]return = trueTaking the longest word first, sunflow, leaves erpot, which cannot be split. But sun + flower + pot works, so the answer is true.
Constraints
1 <= s.length <= 10001 <= wordDict.length <= 5001 <= wordDict[i].length <= 20sand everywordDict[i]consist of lower-case English letters.- All words in
wordDictare different.
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Dictionary SegmentsGoogle · PHONE SCREENGoogle interview questions
- Word BreakBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Longest Common URL History RunDatadog · PHONE SCREENDatadog interview questions
- Word Break IIWex · PHONE SCREEN
- Indexed Proximity SearchStripe · PHONE SCREENStripe interview questions
- Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
- Longest String ChainVisa · OAVisa interview questions
- Word Break with a Reusable DictionaryMeta · ONSITE INTERVIEWMeta interview questions
- Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)