Find the Smallest String After One Decrement
Point72Machine Learning Engineer · Technical ScreenLast updated
This question evaluates string manipulation, lexicographic ordering, and reasoning about local character transformations including wrap-around behavior.
You are given a string s consisting only of lowercase English letters.
You must perform exactly one operation:
- Choose one non-empty contiguous substring of
s. - Replace every character in that substring with the previous character in the alphabet.
- For example,
bbecomesa,cbecomesb, and so on. - The character
awraps around and becomesz.
Return the lexicographically smallest string that can be obtained after exactly one operation.
Example:
Input: s = "cbabc"
Output: "baabc"
Explanation: Choose the substring "cb" and decrement it to "ba", producing "baabc".
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.