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

Easy

614

14

Given a string `s`

consisting of **only** the characters `'a'`

and `'b'`

, return `true`

*if every *

`'a'`

`'b'`

`false`

.

**Example 1:**

Input:s = "aaabbb"Output:trueExplanation:The 'a's are at indices 0, 1, and 2, while the 'b's are at indices 3, 4, and 5. Hence, every 'a' appears before every 'b' and we return true.

**Example 2:**

Input:s = "abab"Output:falseExplanation:There is an 'a' at index 2 and a 'b' at index 1. Hence, not every 'a' appears before every 'b' and we return false.

**Example 3:**

Input:s = "bbb"Output:trueExplanation:There are no 'a's, hence, every 'a' appears before every 'b' and we return true.

**Constraints:**

`1 <= s.length <= 100`

`s[i]`

is either`'a'`

or`'b'`

.

Accepted

55.3K

Submissions

77.8K

Acceptance Rate

71.2%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved