Word Break Problem

00:00
MediumDynamic ProgrammingStringHashSetBFS
AmazonGoogleFacebook

Given a string s and a dictionary of words, determine if s can be segmented into space-separated sequence of dictionary words.

Examples

Input → s='leetcode', wordDict=['leet','code']
Output → True
Input → s='applepenapple', wordDict=['apple','pen']
Output → True
Input → s='catsandog', wordDict=['cats','dog','sand','and','cat']
Output → False