Good morning! Here's our prompt for today.
We're given a string and need to see if it can be broken down into words from a dictionary array. For example:
JAVASCRIPT
1const str = "applecomputer";
2const dictArr = ["apple", "computer"];
3stringBreakdown(str, dictArr);
4// trueAssuming that there are no repeats in the dictionary array, can you write a method that will return true if the string can be broken down into words from the array, or false if not?

Constraints
- Length of the string <=
1000 - The string is made up of
ASCIIcharacters (all or some of it) - Expected time complexity :
O(n^2) - Expected space complexity :
O(n)
Try to solve this here or in Interactive Mode.
How do I practice this challenge?
xxxxxxxxxx29
def str_breakdown(s, dict_arr): # fill in return s​​import unittest​​class Test(unittest.TestCase): def test_1(self): assert ( str_breakdown("crazyrichasians", ["crazy", "rich", "movie", "asians"]) == True ) print( "PASSED: Expect str_breakdown('crazyrichasians', ['crazy', 'rich', 'movie', 'asians']) to return True" )​ def test_2(self): assert str_breakdown("lockcombination", ["lock", "combo"]) == False print( "PASSED: Expect str_breakdown('lockcombination', ['lock', 'combo']) to return False" )​​if __name__ == "__main__": unittest.main(verbosity=2) print("Nice job, 2/2 tests passed!")​OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment
Here's how we would solve this problem...
How do I use this guide?
Access all course materials today
The rest of this tutorial's contents are only available for premium members. Please explore your options at the link below.

