Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.