All problems
1058MediumArrayHash TableString

Matching Lookups Against a Word List

Tracked in this browser only
Write code

Trains the technique from

LeetCode 966Vowel Spellchecker

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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