Problem
Ask
Submissions

Problem: Vowel Spellchecker

Medium
30 min
Explore how to design a vowel spellchecker that handles capitalization and vowel mismatches efficiently by using hash maps. Learn to apply precedence rules for matching queries to a word list, improving your ability to recognize and solve similar pattern-based coding problems.

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 word lengths must still be equal and consonants must match exactly (case insensitively).

The spellchecker uses the following precedence rules to determine the correct match:

  • If the query exactly matches a word in wordlist (case sensitive), return that exact word.

  • Otherwise, if the query matches a word in wordlist up to capitalization differences, return the first such match in wordlist.

  • Otherwise, if the query matches a word in wordlist up to vowel errors (case insensitive), return the first such match in wordlist.

  • 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' (and their uppercase counterparts for case insensitive comparison). All other letters are treated as consonants.

Constraints:

  • 11 \leq wordlist.length, queries.length 5000\leq 5000

  • 11 \leq wordlist[i].length, queries[i].length 7\leq 7

  • wordlist[i] and queries[i] consist only of English letters.

Problem
Ask
Submissions

Problem: Vowel Spellchecker

Medium
30 min
Explore how to design a vowel spellchecker that handles capitalization and vowel mismatches efficiently by using hash maps. Learn to apply precedence rules for matching queries to a word list, improving your ability to recognize and solve similar pattern-based coding problems.

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 word lengths must still be equal and consonants must match exactly (case insensitively).

The spellchecker uses the following precedence rules to determine the correct match:

  • If the query exactly matches a word in wordlist (case sensitive), return that exact word.

  • Otherwise, if the query matches a word in wordlist up to capitalization differences, return the first such match in wordlist.

  • Otherwise, if the query matches a word in wordlist up to vowel errors (case insensitive), return the first such match in wordlist.

  • 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' (and their uppercase counterparts for case insensitive comparison). All other letters are treated as consonants.

Constraints:

  • 11 \leq wordlist.length, queries.length 5000\leq 5000

  • 11 \leq wordlist[i].length, queries[i].length 7\leq 7

  • wordlist[i] and queries[i] consist only of English letters.