Vowel Spellchecker
Given a wordlist, implement a spellchecker that converts each query word into a correct word.
For a given query word, the spellchecker handles two categories of spelling mistakes:
- Capitalization: If the
querymatches a word inwordlistcase-insensitively, return the matching word with the same case as it appears inwordlist. - Vowel Errors: If, after replacing the vowels
('a', 'e', 'i', 'o', 'u')of thequeryword with any vowels individually, it matches a word inwordlistcase-insensitively, return the matching word with the same case as it appears inwordlist.
The spellchecker operates under the following precedence rules:
- When the
queryexactly matches a word inwordlistcase-sensitively, return the same word back. - When the
querymatches a word up to capitalization, return the first such match inwordlist. - When the
querymatches a word up to vowel errors, return the first such match inwordlist. - If the
queryhas no matches inwordlist, return the empty string.
Given queries, return a list of words answer, where answer[i] is the correct word for query = queries[i].
Example 1
Input
wordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]Output
["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]Each query is resolved by exact match first, then capitalization match, then vowel-error match, and otherwise becomes an empty string.
Example 2
Input
wordlist = ["yellow"], queries = ["YellOw"]Output
["yellow"]The query matches the word in
wordlist case-insensitively, so the original wordlist casing is returned.Constraints
- 1 <= wordlist.length, queries.length <= 5000
- 1 <= wordlist[i].length, queries[i].length <= 7
- wordlist[i] and queries[i] consist only of only English letters.