Show problems as
Classic problem #966MediumArrayHash TableString

Vowel Spellchecker

Real-world version: Matching Lookups Against a Word List
Tracked in this browser only
Read Vowel Spellchecker on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A word list is given as entries and a run of lookups as asks, both made of English letters in either case.

Answer each lookup by the first of these rules that finds a match, and where a rule finds several matches, the earliest such entry in entries wins:

  • the lookup matches an entry exactly, letter for letter and case for case: answer that entry;
  • the lookup matches an entry once case is ignored: answer that entry;
  • the lookup matches an entry once case is ignored and every vowel is treated as interchangeable with every other vowel, the vowels being a, e, i, o and u: answer that entry;
  • nothing matches at all: answer the empty string.

Return the answers in the order the lookups are given.

Examples

Example 1

Input
entries = ["Book", "book", "cat"], asks = ["Book", "BOOK", "beek", "cot", "dog"]
Output
["Book", "Book", "Book", "cat", ""]

The first lookup matches an entry exactly. The second matches once case is ignored, and the earliest entry doing so is Book. The third differs only in its vowels, again answering Book. The fourth differs only in its vowels from cat. The last matches nothing at all.

Example 2

Input
entries = ["yellow"], asks = ["YellOw"]
Output
["yellow"]

No entry matches case for case, but folding case away leaves the one entry, so it is the answer with its own spelling kept.

Example 3

Input
entries = ["cat"], asks = ["dog"]
Output
[""]

The lookup differs from the only entry in a consonant, which no rule forgives, so nothing matches.

Constraints

  • 1 <= entries.length <= 5000
  • 1 <= asks.length <= 5000
  • 1 <= entries[i].length <= 7
  • 1 <= asks[i].length <= 7
  • Every string is made of English letters.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def spellchecker(entries: list[str], asks: list[str]) -> list[str]:
Java
public String[] spellchecker(String[] entries, String[] asks)