3722. Lexicographically Smallest String After Reverse
You are given a string
sof lengthnconsisting of lowercase English letters.You must perform exactly one operation by choosing any integer
ksuch that1 <= k <= nand either:
- reverse the first
kcharacters ofs, or- reverse the last
kcharacters ofs.Return the lexicographically smallest string that can be obtained after exactly one such operation.
A string
ais lexicographically smaller than a stringbif, at the first position where they differ,ahas a letter that appears earlier in the alphabet than the corresponding letter inb. If the firstmin(a.length, b.length)characters are the same, then the shorter string is considered lexicographically smaller.
1 | class Solution { |