AlgoLounge

Alphabetical Order Checker

easy

Determine if the characters in a string are in non-decreasing alphabetical order.

Examples

Example 1

Input:  "abc"
Output: true

Example 2

Input:  "aab"
Output: true

'a' ≤ 'a' ≤ 'b' (non-decreasing)

Example 3

Input:  "ba"
Output: false

Example 4

Input:  ""
Output: true

Empty string is considered ordered

Constraints

  • Empty strings and single characters are considered ordered
  • Repeating characters are allowed (non-decreasing)
TypeScript
Loading editor…
List of test cases (10)
Case 1
s = "abc"
Case 2
s = "aab"
Case 3
s = "ba"
Case 4
s = ""
Case 5
s = "abcdefghijklmnopqrstuvwxyz"
Case 6
s = "aaabbbccc"
Case 7
s = "xyz"
Case 8
s = "zyx"
Case 9
s = "a"
Case 10
s = "abcba"