JuniorString

Check if All A's Appears Before All B's

Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.

Example 1
Inputs = "aaabbb"
Outputtrue
The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5, so every 'a' appears before every 'b'.
Example 2
Inputs = "abab"
Outputfalse
There is an 'a' at index 2 and a 'b' at index 1, so not every 'a' appears before every 'b'.

Constraints

  • 1 <= s.length <= 100
  • s[i] is either 'a' or 'b'.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate