FastPrepLexicographically Smallest String After Substring Operation

Lexicographically Smallest String After Substring Operation

Point72 logoPoint72● MediumFULLTIMEOA
Learn

Problem statement

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.

Function

solveLexicographicallySmallestSubstringOperation(input: String) → String[]

Examples

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

See Point72 hiring insights
public String[] solveLexicographicallySmallestSubstringOperation(String input) {
    // write your code here
}
input"cbabc"
expected["baabc"]
Checking account…