LeetCode Entry
2124. Check if All A's Appears Before All B's
All 'a' before all 'b'
2124. Check if All A’s Appears Before All B’s easy substack youtube
https://dmitrysamoylenko.com/leetcode/

Join me on Telegram
Problem TLDR
All ‘a’ before all ‘b’
Intuition
Check the regex ^ab$ or check the forbidden pattern ba
Approach
- all aaa or all bbb considered true
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\)
Code
fun checkString(s: String)=
"ba" !in s
pub fn check_string(s: String) -> bool {
!s.contains("ba")
}
Comments