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