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
Pattern Matching: Wildcards and Digits (Extended)
00:00
5 left

Pattern Matching: Wildcards and Digits (Extended)

HardPython

Problem

Rokt surface rules can represent repeated arbitrary characters compactly. Given an encoded pattern s1 and a candidate string s2, return True if the pattern matches the entire string, otherwise return False.

In s1, each . matches exactly one arbitrary character. A maximal run of decimal digits represents that many consecutive arbitrary characters. For example, a3b matches aXYZb, and a12b matches a followed by any 12 characters and then b. Every other character is a literal and must match exactly. Digit runs are counts, not literal characters.

The pattern must consume all of s2; partial matches are invalid. Do not expand counted wildcards into an intermediate string because a count may be much larger than the encoded pattern.

Formal Specification

Implement match_pattern(s1, s2), where both inputs are strings. Return a boolean indicating whether the complete pattern s1 matches the complete string s2.

Constraints

  • 1 <= len(s1) <= 100000
  • 0 <= len(s2) <= 1000000
  • Each digit run represents an integer from 0 through 10^18
  • s1 contains ASCII letters, '.', and decimal digits
  • A digit run may represent zero wildcard characters

Function Signature

def match_pattern(s1, s2):
Interviewer

Your question is Pattern Matching: Wildcards and Digits (Extended). 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.