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.
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.
- CamelCase Pattern Matching
- Number of words in a camelcase sequence
- WildCard pattern matching having three symbols ( * , + , ? )
- Dynamic Programming | Wildcard Pattern Matching | Linear Time and Constant Space
- Wildcard Pattern Matching
- Convert Infix To Prefix Notation
- Check if the given string of words can be formed from words present in the dictionary
- Count words that appear exactly two times in an array of words
- Given a sequence of words, print all anagrams together | Set 2
- Print all valid words that are possible using Characters of Array
- Java ArrayList to print all possible words from phone digits
- Print all possible combinations of words from Dictionary using Trie
- Given a sequence of words, print all anagrams together | Set 1
- Print all funny words in a string
- Print all possible words from phone digits
- Print all the non-repeating words from the two given sentences
- Given a sequence of words, print all anagrams together using STL
- Print all numbers up to N in words in lexicographical order
- String matching where one string contains wildcard characters
- Longest prefix matching - A Trie based solution in Java
Improved By : princi singh