LeetCode Entry

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

22.11.2026 easy 2026 kotlin rust

All 'a' before all 'b'

2124. Check if All A’s Appears Before All B’s easy substack youtube

https://dmitrysamoylenko.com/leetcode/

22.11.2026.webp

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