2734. Lexicographically Smallest String After Substring Operation
Medium
30 Points
String
Greedy
Given a string s consisting of lowercase English letters. Perform the following operation:
Return the lexicographically smallest string after performing the operation.
Examples
Example 1
Input: s = "cbabc"
Output: "baabc"
Explanation:
Perform the operation on the substring starting at index 0, and ending at index 1 inclusive.
Example 2
Input: s = "aa"
Output: "az"
Explanation:
Perform the operation on the last letter.
Example 3
Input: s = "acbbc"
Output: "abaab"
Explanation:
Perform the operation on the substring starting at index 1, and ending at index 4 inclusive.
Example 4
Input: s = "leetcode"
Output: "kddsbncd"
Explanation:
Perform the operation on the entire string.
Constraints
1 <= s.length <= 3 * 105
s consists of lowercase English letters
2734. Lexicographically Smallest String After Substring Operation
Medium
30 Points
String
Greedy
Given a string s consisting of lowercase English letters. Perform the following operation:
Return the lexicographically smallest string after performing the operation.
Examples
Example 1
Input: s = "cbabc"
Output: "baabc"
Explanation:
Perform the operation on the substring starting at index 0, and ending at index 1 inclusive.
Example 2
Input: s = "aa"
Output: "az"
Explanation:
Perform the operation on the last letter.
Example 3
Input: s = "acbbc"
Output: "abaab"
Explanation:
Perform the operation on the substring starting at index 1, and ending at index 4 inclusive.
Example 4
Input: s = "leetcode"
Output: "kddsbncd"
Explanation:
Perform the operation on the entire string.
Constraints
1 <= s.length <= 3 * 105
s consists of lowercase English letters
Lexicographically Smallest String After Substring Operation - Practice Coding | SlaveCode