Word break
HardGiven a string and a list of words, write a function that determins if the string can be formed from the a combination of the given words.
For example, given the following input:
s = 'thedogiscool'word_list = ['the', 'cat', 'dog', 'cool', 'is', 'uncool']
Your function should return
True
since the string can be formed from ['the', 'dog', 'cool', 'is']
.However, the inputs:
s = 'hellosun'word_list = ['hello', 'moon', 'hi']
should return
False
.Try it first
Solution
8 Essential Recursion & Dynamic Programming Coding Interview Problems
Master Recursion & Dynamic Programming by trying the coding challenges below.
- 1.FibonacciEasy
- 2.Unique pathsMedium
- 3.KnapsackMedium
- 4.Subset sumMedium
- 5.Power setMedium
- 6.Coin changeMedium
- 7.Word breakHard
- 8.Longest common subsequenceHard