Let \$ A \$ represent the alphabet, such that \$ A_1 = \$ a
and \$ A_{26} = \$ z
.
Let's define that a word \$ W = w_1 w_2 ... w_n \$ (where \$ w_c \in A\$) is in standard order if and only if:
- \$ w_1 = A_1 \$, and
- for \$ 2 \le i \le n \$, if \$ w_i = A_x \$ then \$ w_j = A_{x-1} \$ for some \$ j < i \$ and some \$x\$.
In other words, the word must start with a
and each other letter can only appear in a word if the preceding letter in the alphabet has already appeared. Equivalently, if we take only the first appearance of each unique letter in the word, the resulting word is a prefix of the alphabet.
For example, ac
is not in standard order, because there is no b
before the c
.
The following relationships exist between the property of standard order and some others (this list is mainly here for searchability):
- A word is a valid rhyme scheme if and only if it is in standard order (related challenge)
- A word in standard order is the lexicographically earliest among all its isomorphs
- The number of words of length \$ n \$ which are in standard order is the \$ n \$th Bell number (related challenge)
Task
Given a string of letters, determine if it is in standard order according to the Latin alphabet.
Test cases
Truthy:
a
aaa
abab
aabcc
abacabadabacaba
abcdefghijklmnopqrstuvwxyzh
Falsey:
b
ac
bac
abbdc
bcdefghijklmnopqrstuvwxyza
abracadabra
Rules
- You should represent true and false outputs using any two distinct values of your choice
- You may assume the input is non-empty and only contains lowercase ASCII letters
- Alternatively, you may accept input as a list of integers representing alphabet indices (in either \$ [0, 25] \$ or \$ [1, 26] \$, at your option)
- You may use any standard I/O method
- Standard loopholes are forbidden
- This is code-golf, so the shortest code in bytes wins