मध्यम 0 हल किए गए 0% स्वीकृति

Spell Checker

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

आप क्या सीखेंगे

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

समस्या

अनुवाद दिखाएँ

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.

सीमाएँ

0 ≤ dictionary size ≤ 2,000

0 ≤ length of text ≤ 10,000

उदाहरण

उदाहरण 1
इनपुट:
dictionary = ["the", "cat", "sat", "on", "mat"]
text = "The cat sat on teh mat, the cta!"

अपेक्षित आउटपुट:
expected = ["teh", "cta"]
इनपुट:
std::vector<std::string> dictionary = {"the", "cat", "sat", "on", "mat"};
std::string text = "The cat sat on teh mat, the cta!";

अपेक्षित आउटपुट:
std::vector<std::string> expected = {"teh", "cta"};
इनपुट:
string[] dictionary = new string[] {"the", "cat", "sat", "on", "mat"};
string text = "The cat sat on teh mat, the cta!";

अपेक्षित आउटपुट:
string[] expected = new string[] {"teh", "cta"};

व्याख्या

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

उदाहरण 2
इनपुट:
dictionary = ["Don't", "stop"]
text = "don't STOP, dont stop dont"

अपेक्षित आउटपुट:
expected = ["dont"]
इनपुट:
std::vector<std::string> dictionary = {"Don't", "stop"};
std::string text = "don't STOP, dont stop dont";

अपेक्षित आउटपुट:
std::vector<std::string> expected = {"dont"};
इनपुट:
string[] dictionary = new string[] {"Don't", "stop"};
string text = "don't STOP, dont stop dont";

अपेक्षित आउटपुट:
string[] expected = new string[] {"dont"};

व्याख्या

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

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Lowercase the dictionary words once when you build the set.

संकेत 2

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

संकेत 3

Keep a second set of words already reported.

अपेक्षित जटिलता

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

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

हर कोडर का सबसे अच्छा पास हुआ समाधान। तेज़, कम मेमोरी वाले और बेहतर रेटिंग वाले समाधान ऊपर रहते हैं।

अभी कोई पास हुआ समाधान नहीं है। इसे हल करें और पहला स्थान पाएँ।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।