Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Search for Substring and Complexity

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

Your question is Search for Substring and Complexity. 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

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 def 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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output