Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Build a Spell Checker

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Build a Spell Checker. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Capsule needs to validate text entered into a prescription note. Given a string text and an array valid_words, identify words that are misspelled or incorrectly capitalized.

Return a dictionary with three lists:

  1. misspelled: words whose lowercase form does not appear in valid_words, preserving text order and spelling.
  2. uncapitalized_sentence_starts: words at the beginning of the text or immediately after ., !, or ? that begin with a lowercase letter.
  3. uncapitalized_proper_nouns: words that begin with a lowercase letter but match, case-insensitively, a proper noun in valid_words. A proper noun is represented by a word beginning with an uppercase letter followed by lowercase letters, such as Robert or Japan.

Words may contain letters and an optional apostrophe, such as patient's. Ignore punctuation when identifying words. Preserve duplicate occurrences in the output lists.

Constraints

  • 1 <= len(text) <= 10^5
  • 1 <= len(valid_words) <= 10^4
  • Each valid word contains alphabetic characters and may contain one apostrophe
  • Matching misspellings is case-insensitive
  • Preserve duplicate occurrences and original token spelling

Function Signature

def spell_check(text, valid_words):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output