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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Search for Substring and Complexity
00:00
5 left

Search for Substring and Complexity

MediumPython

Problem

How would you find a given string in a longer string, and what is its asymptotic complexity?

Asked in the First Technical Phone Screen, France interviewer, 30 min. Implement substring search using an efficient algorithm and return the starting index of the first match.

Input and Output

Implement substring_search(text, pattern). Return the zero-based starting index, or -1 if the pattern does not occur. Return 0 when pattern is empty.

Constraints

  • 0 <= len(text) <= 1000
  • 0 <= len(pattern) <= 1000
  • Return the first zero-based match index
  • Return 0 for an empty pattern

Function Signature

def substring_search(text, pattern):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

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.