Magicsheet logo

Vowel Spellchecker

Medium
78.9%
Updated 6/1/2025

Vowel Spellchecker

What is this problem about?

The Vowel Spellchecker coding problem involves creating a robust system that can correct misspelled words based on a set of dictionary rules. Unlike a simple exact-match search, this problem requires handling two specific types of "errors": capitalization differences and vowel substitutions. Given a list of valid words (a dictionary) and a set of query words, the goal is to return the best possible match for each query. The matching priority is crucial: first, look for an exact match; if not found, look for a case-insensitive match; if still not found, look for a match where all vowels are treated as interchangeable. If no match exists even after these checks, the system returns an empty string.

Why is this asked in interviews?

This is a classic Vowel Spellchecker interview question because it tests a candidate's ability to implement multi-level matching logic efficiently. Companies like Microsoft and Meta often use such problems to evaluate how well an engineer can manage state using hash tables. It also assesses your understanding of string normalization techniques—transforming data into a standard format (like lowercase or vowel-masked) to facilitate quick lookups. Handling multiple edge cases while maintaining optimal time complexity is a key skill in software engineering.

Algorithmic pattern used

The primary algorithmic pattern used here involves the Hash Table interview pattern. To ensure the spellchecker is fast, we don't want to iterate through the dictionary for every query. Instead, we pre-process the dictionary into several hash maps: one for exact matches, one for case-insensitive matches (storing the first occurrence), and one for vowel-masked matches (also storing the first occurrence). This pre-computation allows each query to be resolved in O(1) or O(L) time, where L is the length of the word.

Example explanation

Suppose our dictionary contains ["Yellow", "Apple"].

  1. If we query "Yellow", it's an exact match.
  2. If we query "yEllOw", the exact match fails. We then look at the case-insensitive map. "yEllOw" converted to lowercase is "yellow", which matches "Yellow" (the first lowercase match in the dictionary).
  3. If we query "Yallaw", both exact and case-insensitive matches fail. We then mask the vowels: "Yllw". Our dictionary word "Yellow" also masks to "Yllw". Thus, "Yallaw" matches to "Yellow".
  4. If we query "Yllw", no match is found, so we return "".

Common mistakes candidates make

A frequent error is not respecting the "first occurrence" rule for case-insensitive and vowel-insensitive matches. If the dictionary is ["Apple", "apply"], and the query is "APPLY", the answer should be "apply", but if not handled carefully, a dev might return the wrong instance or overwrite entries in their hash map. Another mistake is forgetting that 'y' is not typically treated as a vowel in these specific coding challenges.

Interview preparation tip

When working with string and hash table problems, always consider the trade-off between space and time. Pre-calculating normalized versions of your data is almost always better than re-processing it during the query phase. Practice explaining your normalization logic clearly, as this demonstrates structured thinking.

Similar Questions