Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Word Break

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Word Break. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Uber Eats may need to validate whether a normalized search string can be assembled from known menu or query tokens. Given a string s and a list wordDict, determine whether s can be segmented into one or more dictionary words. A dictionary word may be used multiple times.

Formal Specification

Implement word_break(s, wordDict).

  • Input: s, a lowercase string, and wordDict, a list of lowercase strings.
  • Output: Return True if s can be fully segmented into dictionary words. Otherwise, return False.
  • Words must cover the entire string, in order, with no unmatched characters.

Constraints

  • 1 <= len(s) <= 300
  • 1 <= len(wordDict) <= 1,000
  • 1 <= len(wordDict[i]) <= 20
  • s and every dictionary word contain only lowercase English letters
  • Duplicate dictionary words may appear

Function Signature

def word_break(s, wordDict):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output