Shortlex predecessor Please note the special scoring for this challenge. 

Given a non-empty string made of a-z, output the string immediately before it in the shortlex order.

Shortlex order

We enumerate strings in shortlex order by first listing the strings of length 0, then those of length 1, then length 2, and so on, putting them in alphabetical order for each length. This gives an infinite list of all strings. Said a bit differently, this sorts strings by length, tiebroken alphabetically.

For strings a-z as used in the challenge, this list goes (abridged):

(empty string)
a
b
c
...
z
aa
ab
...
az
ba
bb
...
zy
zz
aaa
aab
...


Scoring

Answers will be compared in shortlex order, with earlier being better.

Like in code golf, fewest bytes wins, but there's a tiebreak for same-length answers in favor of coming first alphabetically. This means that you'll want to further "golf" your answer to use characters with lower code points where this doesn't hurt its length. Characters nearer to the start are more important.

For non-ASCII languages, answers are treated as a sequence of bytes. Use the byte order of the code page to compare characters, not their UTF encoding. 

For your answer's header, you can just put the code's length and say when you've outgolfed a same-length answer in the same language. You could also put the code's position in shortlex order if that number is not too long.

Input and output

The input string will be between 1 and 10 characters long, and consist only of letters a-z. As per site defaults, you may do I/O with strings as lists of characters or code points. The letters should be lowercase (code points 97-122).

Test cases

The first output is the empty string.

a -&gt; 
c -&gt; b
z -&gt; y
aa -&gt; z
az -&gt; ay
ba -&gt; az
aaa -&gt; zz
zaa -&gt; yzz
golf -&gt; gole 
bzaaaaaaaa -&gt; byzzzzzzzz
zzzzzzzzzz -&gt; zzzzzzzzzy


Related: Smaller Strings in Printable ASCII base, Counting in bijective base 62
Haskell, 64, 63, 56, 55 bytes


c is an infinite list of all strings composed of 97..122 in shortlex order.
\x y -&gt; last$fst$span(/=x)y gives the predecessor of x in y




a b=last$fst$span(/=b)c
c=[]:[d++[e]|d&lt;-c,e&lt;-[97..122]]


Try it online!


1 byte saved by using code points: [97..122] vs. ['a'..'z']
9 bytes saved by ovs
1 bytes saved by Laikoni


Shortlex optimality

To get the lowest-ordered version of this code:


Each variable is chosen to be the smallest, front-to-back
The two lines are sorted (' ' &lt; '=')