Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Home
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets

Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Back to Problems

966. Vowel Spellchecker

Medium51.4% Acceptance
ArrayHash TableString
Asked by:
T
Thumbtack
ProblemSolutions (4)VideosCompanies (1)Notes

Problem Statement

Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.

For a given query word, the spell checker handles two categories of spelling mistakes:

  • Capitalization: If the query matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the case in the wordlist.
    • Example: wordlist = ["yellow"], query = "YellOw": correct = "yellow"
    • Example: wordlist = ["Yellow"], query = "yellow": correct = "Yellow"
    • Example: wordlist = ["yellow"], query = "yellow": correct = "yellow"
  • Vowel Errors: If after replacing the vowels ('a', 'e', 'i', 'o', 'u') of the query word with any vowel individually, it matches a word in the wordlist (case-insensitive), then the query word is returned with the same case as the match in the wordlist.
    • Example: wordlist = ["YellOw"], query = "yollow": correct = "YellOw"
    • Example: wordlist = ["YellOw"], query = "yeellow": correct = "" (no match)
    • Example: wordlist = ["YellOw"], query = "yllw": correct = "" (no match)

In addition, the spell checker operates under the following precedence rules:

  • When the query exactly matches a word in the wordlist (case-sensitive), you should return the same word back.
  • When the query matches a word up to capitlization, you should return the first such match in the wordlist.
  • When the query matches a word up to vowel errors, you should return the first such match in the wordlist.
  • If the query has no matches in the wordlist, you should return the empty string.

Given some 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"]

Example 2:

Input: wordlist = ["yellow"], queries = ["YellOw"]
Output: ["yellow"]

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.
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions

Approach

The key idea in #966 Vowel Spellchecker is to simulate the spellchecker rules in priority order: exact match, case-insensitive match, and vowel error match. Efficient lookup is achieved using hash tables.

First, store all words in a set to quickly detect exact matches. Next, create a map from the lowercase version of each word to its first occurrence in the word list. This helps resolve case-insensitive queries. Finally, build another hash map where each word is converted to a vowel-normalized form (for example, replacing vowels with a placeholder like *). This structure allows matching queries that differ only by vowel substitutions.

For each query, check the rules sequentially: exact match, lowercase match, then vowel-normalized match. If none exist, return an empty string. With preprocessing and constant-time lookups using hash maps, the solution efficiently handles all queries.

Complexity

ApproachTime ComplexitySpace Complexity
Hash Set + Hash Map with Vowel NormalizationO(W * L + Q * L)O(W * L)

Video Solution Available

Greg Hogg

View all video solutions

Solutions (4)

Hash Maps for Different Match Types

This approach uses three types of hash maps:

  • Exact Match: This stores the words in their original form for exact matching.
  • Case-Insensitive Map: This converts all words to lowercase for handling capitalization errors and maps them to their original form for case restoration.
  • Vowel-Insensitive Map: This converts all vowels in words to a placeholder (e.g., '*'), enabling matching words that differ only by vowel substitutions.
For each query, the spellchecker checks in the order of exact matches, case-insensitive matches, and vowel-insensitive matches and returns the first match found.

Time Complexity: O(N + M) per query, where N is the length of the wordlist and M is the length of the longest query.
Space Complexity: O(N), to store the dictionaries for the wordlist.

PythonJava
1def spellChecker(wordlist, queries):
2    def normalize_word(word):
3        return ''.join(['*' if c in 'aeiouAEIOU' else c for c in word])
4    exact_matches = set(wordlist)
5    case_matches = {w.lower(): w for w in reversed(wordlist)}
6    vowel_matches = {}
7    for w in reversed(wordlist):
8        vw = normalize_word(w.lower())
9        if vw not in vowel_matches:
10            vowel_matches[vw] = w
11    def find_match(query):
12        if query in exact_matches:
13            return query
14        low_query = query.lower()
15        if low_query in case_matches:
16            return case_matches[low_query]
17        vow_query = normalize_word(low_query)
18        if vow_query in vowel_matches:
19            return vowel_matches[vow_query]
20        return ""
21    return [find_match(query) for query in queries]

Explanation

This solution initializes three dictionaries for exact, case-insensitive, and vowel-insensitive matches. The normalize_word function transforms words by replacing all vowels with '*'. For each query, the solution checks the query against these dictionaries and returns results based on the first successful match.

Trie with Search Functions for Different Match Types

This approach utilizes a trie data structure to accommodate the various search conditions:

  • Exact Match: Regular trie for exact word representation.
  • Case-Insensitive Match: Insert both the lowercase and original version in the trie and search in case-insensitive fashion.
  • Vowel-Insensitive Match: Insert words into the trie after transforming their vowels to a common character, like '*'.
For each query, iterate through trie searches, trying to find matches in the priority of exact matches, case-insensitive matches, and vowel-insensitive matches.

Time Complexity: O(N + M) per query, where N is the length of the wordlist and M is the length of the longest query.
Space Complexity: O(N), for storing each transformed mapping in the maps used.

C++JavaScript
1#include <unordered_map>
2#include <unordered_set>
3#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class Spellchecker {
public:
    vector<string> spellchecker(vector<string>& wordlist, vector<string>& queries) {
        unordered_set<string> exactMatch(wordlist.begin(), wordlist.end());
        unordered_map<string, string> caseInsensitiveMap;
        unordered_map<string, string> vowelInsensitiveMap;

        for (auto it = wordlist.rbegin(); it != wordlist.rend(); ++it) {
            string lowerWord = toLower(*it);
            caseInsensitiveMap[lowerWord] = *it;
            vowelInsensitiveMap[maskVowels(lowerWord)] = *it;
        }

        vector<string> results;
        for (const string& query : queries) {
            if (exactMatch.count(query)) {
                results.push_back(query);
            } else {
                string lowerQuery = toLower(query);
                string vowelMaskedQuery = maskVowels(lowerQuery);
                if (caseInsensitiveMap.count(lowerQuery)) {
                    results.push_back(caseInsensitiveMap[lowerQuery]);
                } else if (vowelInsensitiveMap.count(vowelMaskedQuery)) {
                    results.push_back(vowelInsensitiveMap[vowelMaskedQuery]);
                } else {
                    results.push_back("");
                }
            }
        }
        return results;
    }

private:
    string toLower(const string& word) {
        string res = word;
        transform(res.begin(), res.end(), res.begin(), ::tolower);
        return res;
    }

    string maskVowels(string word) {
        for (char& c : word) {
            if (isVowel(c)) c = '*';
        }
        return word;
    }

    bool isVowel(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
};

Video Solutions

Watch expert explanations and walkthroughs

Junior Software Dev vs Senior Dev solving Valid Anagram

Greg Hogg
0:53693,669 views

Asked By Companies

1 companies
T
Thumbtack

Prepare for Interviews

Practice problems asked by these companies to ace your technical interviews.

Explore More Problems

Notes

Personal Notes

Jot down your thoughts, approach, and key learnings

0 characters

Similar Problems

Two SumEasy
Valid SudokuMedium
Sudoku SolverHard
First Missing PositiveHard
More similar problems

Related Topics

ArrayHash TableString

Problem Stats

Acceptance Rate51.4%
DifficultyMedium
Companies1

Practice on LeetCode

Solve with full IDE support and test cases

Solve Now

Frequently Asked Questions

Is Vowel Spellchecker asked in coding interviews?

Yes, this type of problem is common in interviews because it tests string manipulation, hashing, and rule-based matching logic. Companies often use similar problems to evaluate practical use of hash maps.

What is the optimal approach for Vowel Spellchecker?

The optimal approach uses hash tables to enforce the matching priority: exact match, case-insensitive match, and vowel-error match. Preprocessing the word list into normalized forms allows fast lookups for each query.

How does vowel normalization work in Vowel Spellchecker?

Vowel normalization replaces all vowels (a, e, i, o, u) in a lowercase word with a placeholder like '*'. This allows different vowel variations of a word to map to the same key for quick matching.

What data structure is best for solving Vowel Spellchecker?

Hash-based structures such as sets and hash maps work best. They allow constant-time lookups for exact words, lowercase forms, and vowel-normalized patterns.

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

Explanation

This C++ solution builds maps for case-insensitive and vowel-insensitive matches from the wordlist. During querying, each query is transformed and searched against these data structures in the order of priority. It offers a clean way to handle multiple match types while efficiently searching.