2734. Lexicographically Smallest String After Substring Operation
You are given a string
s
consisting of only lowercase English letters. In one operation, you can do the following:
- Select any non-empty substring of
s
, possibly the entire string, then replace each one of its characters with the previous character of the English alphabet. For example, ‘b’ is converted to ‘a’, and ‘a’ is converted to ‘z’.Return the lexicographically smallest string you can obtain after performing the above operation exactly once.
A substring is a contiguous sequence of characters in a string.
A string
x
is lexicographically smaller than a stringy
of the same length ifx[i]
comes beforey[i]
in alphabetic order for the first positioni
such thatx[i] != y[i]
.
1 | class Solution { |