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
Case-Sensitive Word Mismatch Function
00:00
5 left

Case-Sensitive Word Mismatch Function

MediumPython

Problem

A Meta Ads text-processing pipeline compares two whitespace-delimited strings and needs to identify word occurrences that cannot be matched between them. Write a function that returns the unmatched occurrences, preserving their left-to-right order within their original string.

Matching is case sensitive. If a word occurs a times in the first string and b times in the second, return abs(a - b) copies of that word from the string with the larger count. Preserve the order in which returned copies appear in that source string. Punctuation remains part of a word because words are split only on whitespace.

Formal Specification

Implement unmatched_words(s1, s2).

  • Input: Two strings, s1 and s2, containing zero or more whitespace-delimited words.
  • Output: A list of strings containing unmatched word occurrences. Return an empty list when every occurrence can be paired.

Constraints

  • 0 <= len(s1), len(s2) <= 10^5
  • Each string contains at most 2 * 10^4 words
  • Words are separated by arbitrary whitespace
  • Matching is case sensitive
  • Punctuation remains part of a word

Function Signature

def unmatched_words(s1, s2):
Interviewer

Your question is Case-Sensitive Word Mismatch Function. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.