Vowel Spellchecker
Real-world version: Matching Lookups Against a Word ListThe 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,oandu: 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.
def spellchecker(entries: list[str], asks: list[str]) -> list[str]:public String[] spellchecker(String[] entries, String[] asks)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Verifying an Alien DictionaryReal-world version: Catalogue Order Under a Custom Glyph SequenceEasy
- Find Common CharactersReal-world version: Tiles Every Rack Can SupplyEasy
- Destination CityReal-world version: Last Stop On The Courier RunEasy
- Find Words That Can Be Formed by CharactersReal-world version: Signs Spellable From A Tile TrayEasy