Concatenated Words
Updated
Problem statement
Return every word in words that can be built by joining at least two shorter words from the same list.
You may use the same shorter word more than once. A word does not count as built from itself alone. Return the matching words in the same order they appear in words.
Function
findConcatenatedWords(words: String[]) → String[]Examples
Example 1
words = ["cat","cats","dog","catsdog","dogcat","rat"]return = ["catsdog","dogcat"]catsdog is cats followed by dog, and dogcat is dog followed by cat. Both parts are shorter input words each time. None of the other words can be split this way, so the result is ["catsdog","dogcat"].
Example 2
words = ["a","aa","aaa","aaaa"]return = ["aa","aaa","aaaa"]aa is two copies of a, aaa is three copies, and aaaa is four copies. Reusing a word is allowed. a has no shorter word to build it from, so it is left out. The result is ["aa","aaa","aaaa"].
Example 3
words = ["catdog","cat","dog"]return = ["catdog"]catdog is cat followed by dog. Both components are shorter input words. Neither cat nor dog can be formed from two shorter input words, so the result is ["catdog"].
Constraints
1 <= words.length <= 10000.- Words are unique and contain one to thirty lowercase ASCII letters.
- The sum of all word lengths is at most 100000.
More Amazon Phone Screen questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Word Break IIWex · PHONE SCREEN
- Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Word Break IIGoogle · ONSITE INTERVIEWGoogle interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Minimum Insertion Steps to Make a String PalindromeInfosys · ONSITE INTERVIEWInfosys interview questions
- Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
- Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Interleaving StringsCARS24 · ONSITE INTERVIEW
- Word Break IIInMobi · PHONE SCREENInMobi interview questions
- Minimum Stickers to Form a Target StringByteDance · ONSITE INTERVIEWByteDance interview questions