Lexicographically Smallest String After Substring Operation
Updated
Problem statement
You are given a string s of lowercase English letters.
Choose one non-empty substring of s. A substring is a run of letters that sit next to each other. Replace every letter in the substring with the letter just before it in the alphabet. So b becomes a, c becomes b, and a becomes z. You must do this exactly once.
Return the lexicographically smallest string you can get. A string is smaller when it comes first in dictionary order.
Function
smallestString(s: String) → StringExamples
Example 1
s = "cbabc"return = "baabc"Pick the first two letters, cb. Lower them: c becomes b and b becomes a. The string becomes baabc. Picking the a in the middle would turn it into z, which makes the string bigger. No other pick gives a smaller string, so the answer is baabc.
Constraints
1 <= s.length <= 100000scontains only lowercase English letters (atoz)
More Point72 interview questions
- Maximize Array Beauty After DeletionsOA · Seen Aug 2026
- Simulate a Deterministic Finite AutomatonOA · Seen Aug 2026
- Initial Public OfferingOA · Seen Jul 2026
- Test the HypothesisOA · Seen Jul 2026
- Get Triplet CountOA · Seen Jul 2026
- Internet Service Provider Monthly ReportOA · Seen Jul 2026
- Server SelectionOA · Seen Jul 2026
- Best Time to Buy and Sell Stock IIPHONE SCREEN · Seen Aug 2026
- Find Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Aug 2026
- Generate an Optimal Portfolio Trading ReportPHONE SCREEN · Seen Apr 2026
Similar questions at other companies
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Adjacent TranspositionsEpic · OAEpic interview questions