Given an array of strings arr, for every string in the array, print all possible combinations of strings that can be concatenated to make that word.
Input: arr = ["sam", "sung", "samsung"] Output: sam: sam sung: sung samsung: sam sung samsung String 'samsung' can be formed using two different strings from the array i.e. 'sam' and 'sung' whereas 'samsung' itself is also a string in the array. Input: arr = ["ice", "cream", "icecream"] Output: ice: ice cream: cream icecream: ice cream icecream
- Add all the given strings into trie.
- Process every prefix character by character and check if it forms a word from trie by searching.
- If the prefix is present in the trie then add it to the result and proceed further with the remaining suffix in the string.
- Once it reaches the end of the string, print all the combinations found.
Below is the implementation of the above approach:
sam: sam sung: sung samsung: sam sung samsung
- Check if the given string of words can be formed from words present in the dictionary
- Implement a Dictionary using Trie
- Counting the number of words in a Trie
- Sorting array of strings (or words) using Trie
- Count the number of words with given prefix using Trie
- Check if the given Trie contains words starting from every alphabet
- Sorting array of strings (or words) using Trie | Set-2 (Handling Duplicates)
- Python | Words extraction from set of characters using dictionary
- Word formation using concatenation of two dictionary words
- Iterative approach to print all combinations of an Array
- Print all the combinations of a string in lexicographical order
- Print all the combinations of N elements by changing sign such that their sum is divisible by M
- Print all funny words in a string
- Print all possible words from phone digits
- Program to print the given digit in words
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : princiraj1992