Mittel 0 gelöst 0% Erfolgsquote

Spell Checker

List the words in a text that are missing from a dictionary, ignoring case and punctuation.

Das lernst du

  • Load words into a set for fast lookups
  • Split text into words with a character rule
  • Report results in first-seen order without duplicates

Problem

Übersetzung anzeigen

A word processor underlines words it does not know. Load the dictionary into a set (a hash table) so each lookup is fast, then scan the text.

A word is a maximal run of English letters (A-Z, a-z) and apostrophes; every other character (spaces, digits, punctuation) separates words. Words are compared without regard to case, so The matches the dictionary entry the.

Implement spell_checker(dictionary, text).

Input

dictionary: The known words. They may be in any case.

text: The text to check.

Output

Return the misspelled words in lowercase, in the order they first appear in the text, each listed only once. Return an empty list when every word is known.

Einschränkungen

0 ≤ dictionary size ≤ 2,000

0 ≤ length of text ≤ 10,000

Beispiele

Beispiel 1
Eingabe:
dictionary = ["the", "cat", "sat", "on", "mat"]
text = "The cat sat on teh mat, the cta!"

Erwartete Ausgabe:
expected = ["teh", "cta"]
Eingabe:
std::vector<std::string> dictionary = {"the", "cat", "sat", "on", "mat"};
std::string text = "The cat sat on teh mat, the cta!";

Erwartete Ausgabe:
std::vector<std::string> expected = {"teh", "cta"};
Eingabe:
string[] dictionary = new string[] {"the", "cat", "sat", "on", "mat"};
string text = "The cat sat on teh mat, the cta!";

Erwartete Ausgabe:
string[] expected = new string[] {"teh", "cta"};

Erläuterung

teh and cta are not in the dictionary. Case and the comma do not matter for the other words: ["teh", "cta"].

Beispiel 2
Eingabe:
dictionary = ["Don't", "stop"]
text = "don't STOP, dont stop dont"

Erwartete Ausgabe:
expected = ["dont"]
Eingabe:
std::vector<std::string> dictionary = {"Don't", "stop"};
std::string text = "don't STOP, dont stop dont";

Erwartete Ausgabe:
std::vector<std::string> expected = {"dont"};
Eingabe:
string[] dictionary = new string[] {"Don't", "stop"};
string text = "don't STOP, dont stop dont";

Erwartete Ausgabe:
string[] expected = new string[] {"dont"};

Erläuterung

don't keeps its apostrophe and matches; dont is unknown and is listed once: ["dont"].

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

Lowercase the dictionary words once when you build the set.

Hinweis 2

Build the current word character by character and finish it when you meet a non-letter that is not an apostrophe.

Hinweis 3

Keep a second set of words already reported.

Erwartete Komplexität

O(D + T) time, O(D + T) extra space

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Die beste bestandene Lösung jedes Coders. Schnellere, sparsamere und besser bewertete Lösungen stehen weiter oben.

Noch keine bestandene Lösung. Löse sie und hol dir Platz eins.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.