DIY: Concatenated Words
Solve the interview question "Concatenated Words" in this lesson.
We'll cover the following
Problem statement
Provided a list of strings, words
, with unique elements, return all the concatenated words in the given list.
A word that is a combination of at least two or more words is known as a concatenated word.
Input
The input will be a list of strings. The following is an example input:
["cat", "dog", "cats", "lion", "catsdog"]
Output
The output will be a list of concatenated words that exist in words
. The following is an example output:
["catsdog"]
The string catsdog
is the only word made up of cats
and dog
that exist in the list.
Coding exercise
Implement the findAllConcatenatedWords(words)
function, where words
is the list of strings. The function will return a list of concatenated strings.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.