java.lang.Object
g2701_2800.s2734_lexicographically_smallest_string_after_substring_operation.Solution

public class Solution extends Object
2734 - Lexicographically Smallest String After Substring Operation.<p>Medium</p> <p>You are given a string <code>s</code> consisting of only lowercase English letters. In one operation, you can do the following:</p> <ul> <li>Select any non-empty substring of <code>s</code>, possibly the entire string, then replace each one of its characters with the previous character of the English alphabet. For example, &lsquo;b&rsquo; is converted to &lsquo;a&rsquo;, and &lsquo;a&rsquo; is converted to &lsquo;z&rsquo;.</li> </ul> <p>Return <em>the <strong>lexicographically smallest</strong> string you can obtain after performing the above operation <strong>exactly once</strong>.</em></p> <p>A <strong>substring</strong> is a contiguous sequence of characters in a string.</p> <p>A string <code>x</code> is <strong>lexicographically smaller</strong> than a string <code>y</code> of the same length if <code>x[i]</code> comes before <code>y[i]</code> in alphabetic order for the first position <code>i</code> such that <code>x[i] != y[i]</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;cbabc&rdquo;</p> <p><strong>Output:</strong> &ldquo;baabc&rdquo;</p> <p><strong>Explanation:</strong> We apply the operation on the substring starting at index 0, and ending at index 1 inclusive. It can be proven that the resulting string is the lexicographically smallest.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;acbbc&rdquo;</p> <p><strong>Output:</strong> &ldquo;abaab&rdquo;</p> <p><strong>Explanation:</strong> We apply the operation on the substring starting at index 1, and ending at index 4 inclusive. It can be proven that the resulting string is the lexicographically smallest.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;leetcode&rdquo;</p> <p><strong>Output:</strong> &ldquo;kddsbncd&rdquo;</p> <p><strong>Explanation:</strong> We apply the operation on the entire string. It can be proven that the resulting string is the lexicographically smallest.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 3 * 10<sup>5</sup></code></li> <li><code>s</code> consists of lowercase English letters</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details