Given a dictionary of words where each word follows CamelCase notation, print all words in the dictionary that match with a given pattern consisting of uppercase characters only.
CamelCase is the practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter. Common examples include: “PowerPoint” and “WikiPedia”, “GeeksForGeeks”, “CodeBlocks”, etc.
Input: dict = ["Hi", "Hello", "HelloWorld", "HiTech", "HiGeek", "HiTechWorld", "HiTechCity", "HiTechLab"] For pattern "HT", Output: ["HiTech", "HiTechWorld", "HiTechCity", "HiTechLab"] For pattern "H", Output: ["Hi", "Hello", "HelloWorld", "HiTech", "HiGeek", "HiTechWorld", "HiTechCity", "HiTechLab"] For pattern "HTC", Output: ["HiTechCity"] Input: dict = ["WelcomeGeek","WelcomeToGeeksForGeeks", "GeeksForGeeks"] For pattern "WTG", Output: ["WelcomeToGeeksForGeeks"] For pattern "GFG", Output: [GeeksForGeeks] For pattern "GG", Output: No match found
The idea is to insert all dictionary keys into the Trie one by one. Here key refers to only Uppercase characters in original word in CamelCase notation. If we encounter the key for the first time, we need to mark the last node as leaf node and insert the complete word for that key into the vector associated with the leaf node. If we encounter a key that is already in the trie, we update the vector associated with the leaf node with current word. After all dictionary words are processed, we search for the pattern in the trie and print all words that matches the pattern.
Below is the implementation of above idea –
HiTech HiTechCity HiTechLab HiTechWorld
This article is contributed by Aditya Goel. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Number of words in a camelcase sequence
- Wildcard Pattern Matching
- WildCard pattern matching having three symbols ( * , + , ? )
- Dynamic Programming | Wildcard Pattern Matching | Linear Time and Constant Space
- Print all funny words in a string
- Print all possible words from phone digits
- Given a sequence of words, print all anagrams together using STL
- Given a sequence of words, print all anagrams together | Set 1
- Given a sequence of words, print all anagrams together | Set 2
- Print all valid words that are possible using Characters of Array
- Print words of a string in reverse order
- Print number of words, vowels and frequency of each character
- Java ArrayList to print all possible words from phone digits
- Program to print Step Pattern
- Check if the given string of words can be formed from words present in the dictionary
Improved By : princi singh