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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print Strings In Reverse Dictionary Order Using Trie
- Print all possible joints of a Trie constructed from a given list of strings
- Sorting array of strings (or words) using Trie
- Sorting array of strings (or words) using Trie | Set-2 (Handling Duplicates)
- Count the number of words with given prefix using Trie
- Check if the given string of words can be formed from words present in the dictionary
- Print all possible combinations of the string by replacing '$' with any other digit from the string
- Implement a Dictionary using Trie
- Counting the number of words in a Trie
- Check if the given Trie contains words starting from every alphabet
- Iterating over all possible combinations in an Array using Bits
- Print all valid words that are possible using Characters of Array
- Java ArrayList to print all possible words from phone digits
- Print all possible words from phone digits
- Print all the combinations of N elements by changing sign such that their sum is divisible by M
- Print all the combinations of a string in lexicographical order
- Iterative approach to print all combinations of an Array
- Pattern Searching using a Trie of all Suffixes
- Count possible combinations of pairs with adjacent elements from first N numbers
- Word formation using concatenation of two dictionary 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