The "Check if All A's Appears Before All B's interview question" is a string property check. You are given a string consisting only of the characters 'a' and 'b'. You need to determine if every 'a' in the string occurs before every 'b'. Effectively, this means the string should never contain the sequence "ba" as a substring.
Amazon and Microsoft ask the "Check if All A's Appears Before All B's coding problem" to test basic logical reasoning and string traversal. It evaluates whether a candidate can identify the core constraint—that once a 'b' is seen, no more 'a's are allowed. It’s an introductory "String interview pattern" problem that checks for clean, efficient logic.
This problem can be solved with several patterns:
"ba". If it does, return false.seen_b initially set to false. Iterate through the string. If you see 'b', set the flag. If you see 'a' while the flag is true, return false.String: "aaabbb"
"abab""bbb"Think about the "state transition" of the problem. You start in a state where only 'a's are allowed. Once you transition to the 'b' state, you can never go back to 'a'. This mental model helps solve many similar ordering problems in "String interview pattern" tasks.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Number of Segments in a String | Easy | Solve | |
| Check Balanced String | Easy | Solve | |
| Find Special Substring of Length K | Easy | Solve | |
| Make Three Strings Equal | Easy | Solve | |
| Reformat The String | Easy | Solve |