Leetcode Problem 2124. Check if All A's Appears Before All B's
2124. Check if All A's Appears Before All B's
AI Mock Interview
Leetcode Solutions
Linear Scan for 'a' after 'b'
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize a boolean variable
foundB
to
false
to track if we have encountered a 'b'.
Iterate through each character in the string
s
.
If the current character is 'b', set
foundB
to
true
.
If the current character is 'a' and
foundB
is
true
, return
false
as we have found an 'a' after a 'b'.
If we finish iterating through the string without returning
false
, return
true
.
Check for 'b' followed by 'a'
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...