Ctrl K

Every a Before Every b

Easy
Two kinds of visitors stand in a queue: those with a booking (a) and walk-ins (b). The queue is written as a string queue of the letters a and b. The rule says everyone with a booking must stand ahead of every walk-in. Return True if no a comes after any b, and False otherwise. If one of the letters is missing entirely, the rule holds.
Example 1
queue="aaab" → True

All three as come before the only b.

Example 2
queue="abba" → False

The last a comes after two bs.

Example 3
queue="aa" → True

There are no bs, so no a comes after a b.

Constraints
  • 1 ≤ len(queue) ≤ 100
  • queue consists only of the letters a and b
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
queue="aaab"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 155 tests on the server, hidden ones included.