Solution: Vowel Spellchecker
Explore how to build a spellchecker algorithm that corrects capitalization and vowel mistakes leveraging hash map data structures. Understand the step-by-step process to create exact, case-insensitive, and vowel-error hash maps, and apply multiple lookup checks to return the best matching words. This lesson enables you to solve complex string matching problems efficiently using JavaScript, preparing you for coding interview challenges involving hash maps and string manipulation.
We'll cover the following...
Statement
Given a list of correct words wordlist and a list of queries, implement a spellchecker that attempts to match each query word to a correct word from wordlist.
The spellchecker handles two categories of spelling mistakes:
Capitalization: If the query matches a word in wordlist when compared case insensitively, the query is corrected to the matching word as it appears in wordlist.
Vowel Errors: If, after replacing every vowel ('a', 'e', 'i', 'o', 'u') in the query with any vowel individually, the resulting word matches a word in wordlist (case insensitively), the query is corrected to that matching word. The words must be the same length and differ only in which vowels occupy the vowel positions.
The spellchecker uses the following precedence rules to determine the result for each query:
If the query exactly matches a word in
wordlist(case sensitive), return that exact word.Otherwise, if the query matches a word in
wordlistup to capitalization differences, return the first such match inwordlist.Otherwise, if the query matches a word in
wordlistup to vowel errors (case insensitive), return the first such match inwordlist.If no match is found, return the empty string
"".
Return a list answer where answer[i] is the corrected word for queries[i].
Note: Vowels are the characters
'a','e','i','o','u'(both lowercase and uppercase are considered vowels for matching purposes).
Constraints:
...