Problem · String

Lexicographically Smallest String After Substring Operation

MediumPoint72FULLTIMEOA

You are given a string s consisting of lowercase English letters.

You must choose a non-empty substring and perform the following operation on each character in that substring exactly once: replace it with the previous letter in the alphabet (e.g., b → a, c → b). Note that the previous letter of a is z.

Return the lexicographically smallest string you can obtain after performing the operation exactly once.

Input: one line containing the string s.
Output: one line containing the lexicographically smallest result.

Examples
01 · Example 1
input = "cbabc"
return = ["baabc"]

The returned string must match the expected standard output for the sample input.

Constraints

Constraints:

  • 1 <= len(s) <= 100000
  • s contains only lowercase English letters (a to z)
More Point72 problems
drafts saved locally
public String[] solveLexicographicallySmallestSubstringOperation(String input) {
    // write your code here
}
input"cbabc"
expected["baabc"]
checking account