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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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)
- Python | Words extraction from set of characters using dictionary
- Word formation using concatenation of two dictionary words
- Print all possible joints of a Trie constructed from a given list of strings
- Print all the combinations of a string in lexicographical order
- Iterative approach to print all combinations of an Array
- Print all the combinations of N elements by changing sign such that their sum is divisible by M
- Print all possible words from phone digits
- Print all funny words in a string
- Given a sequence of words, print all anagrams together | Set 1
- Given a sequence of words, print all anagrams together | Set 2
- Print all the non-repeating words from the two given sentences
- 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 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