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
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
Validate As Before Bs
00:00
5 left

Validate As Before Bs

EasyPython

Problem

phData pipeline validation uses compact marker strings containing uppercase A, uppercase B, and optional separator characters such as -, _, or spaces. Return True if every A occurs before every B in the string. Characters other than A and B do not affect the ordering.

Once a B has been observed, encountering an A makes the string invalid. The function should process the input in one left-to-right pass and may stop as soon as the ordering is violated.

Formal Specification

Implement ordered_markers(s), where s is a string. Return a Boolean:

  • True if no A appears after any B.
  • False otherwise.

An empty string or a string containing only separators, only A characters, or only B characters is valid.

Constraints

  • 0 <= len(s) <= 10^6
  • s contains only uppercase A, uppercase B, spaces, hyphens, and underscores
  • The input must not be modified
  • Use O(1) auxiliary space

Function Signature

def ordered_markers(s):
Interviewer

Your question is Validate As Before Bs. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.