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 query matches a word in wordlist case-insensitively, return the matching word with the same case as it appears in wordlist.
  • Vowel Errors: If, after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowels individually, it matches a word in wordlist case-insensitively, return the matching word with the same case as it appears in wordlist.

The spellchecker operates under the following precedence rules:

  • When the query exactly matches a word in wordlist case-sensitively, return the same word back.
  • When the query matches a word up to capitalization, return the first such match in wordlist.
  • When the query matches a word up to vowel errors, return the first such match in wordlist.
  • If the query has no matches in wordlist, 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
Inputwordlist = ["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
Inputwordlist = ["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.

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate