30:00
Given a string s made only of the characters 'a' and 'b', return true if every 'a' in s appears before every 'b'. Otherwise, return false.
s
'a'
'b'
true
false
1≤s.length≤1001 \leq s.\text{length} \leq 1001≤s.length≤100
s[i] is either 'a' or 'b'.
s[i]
Run code to see results.
No 'b' seen yet, so the gate is open: an 'a' is still allowed.
s, with the gate at the first 'b'
0
1
2
3
4
5
two-state scanner
seenB = false
Given a string of only 'a' and 'b' characters, decide whether every 'a' comes before every 'b'.