Any other approaches?

Given a string s and a dictionary of strings. The task is to check whether the given string S can be broken into individual words from the dictionary.

Examples:

[CODE]Input:

s = “applepenapple”

words = [“apple”, “pen”];

Output: True

Explanation:

The string “applepenapple” can be broken into “apple pen apple”

Input:

s = “catsandog”

words = [“cats”, “dog”, “sand”, “and”, “cat”]       

Output: False[/CODE]

Just Wondering what can be the other approaches for this example?

Came across this resource, Are there any other resources that you would recommend?

We… cant… tell you “other approaches” if you dont tell us what your approach was. The above is a problem statement, not an approach to solving it.

Also, read the article, and feel like i know even less about what their solution was than before i read it. Very poorly written for anything more than “let me copy your answer”.

Brute Force

And how did you implement it? Why does it work, and what dont you like about it that you think another approach would be better?

(Translation: Tell me you haven’t just copied the code.)