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
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Print Strings In Reverse Dictionary Order Using Trie
- Check if the given string of words can be formed from words present in the dictionary
- Counting the number of words in a Trie
- Count the number of words with given prefix using Trie
- Sorting array of strings (or words) using Trie
- Check if the given Trie contains words starting from every alphabet
- Implement a Dictionary using Trie
- Sorting array of strings (or words) using Trie | Set-2 (Handling Duplicates)
- Word formation using concatenation of two dictionary words
- Python | Words extraction from set of characters using dictionary
- 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
- Given a sequence of words, print all anagrams together | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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