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
Search and Split a String
00:00
5 left

Search and Split a String

MediumPython

Problem

The Zappos Family catalog processes product labels that use a single character as a separator. Implement a custom split operation without calling Python's built-in str.split.

Given a string text, a one-character separator, and a nonnegative integer max_splits, return the pieces produced by scanning from left to right. Split at each separator until max_splits splits have been made. If max_splits is 0, return the entire string as one piece. Preserve empty pieces caused by leading, trailing, or consecutive separators. Any remaining separator characters after the limit belong to the final piece.

Formal Specification

  • Input: text, a string; separator, a string containing exactly one character; and max_splits, a nonnegative integer.
  • Output: A list of strings in scanning order.
  • Do not use str.split or regular expressions.

Constraints

  • 0 <= len(text) <= 10^5
  • separator contains exactly one character
  • 0 <= max_splits <= 10^5
  • Leading, trailing, and consecutive separators must be preserved

Function Signature

def split_by_character(text, separator, max_splits):
Interviewer

Your question is Search and Split a String. 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.