Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Build a Spell Checker
00:00
5 left

Build a Spell Checker

HardPython

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):
Interviewer

Your question is Build a Spell Checker. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.