Class Solution
java.lang.Object
g2601_2700.s2663_lexicographically_smallest_beautiful_string.Solution
2663 - Lexicographically Smallest Beautiful String.<p>Hard</p>
<p>A string is <strong>beautiful</strong> if:</p>
<ul>
<li>It consists of the first <code>k</code> letters of the English lowercase alphabet.</li>
<li>It does not contain any substring of length <code>2</code> or more which is a palindrome.</li>
</ul>
<p>You are given a beautiful string <code>s</code> of length <code>n</code> and a positive integer <code>k</code>.</p>
<p>Return <em>the lexicographically smallest string of length</em> <code>n</code><em>, which is larger than</em> <code>s</code> <em>and is <strong>beautiful</strong></em>. If there is no such string, return an empty string.</p>
<p>A string <code>a</code> is lexicographically larger than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, <code>a</code> has a character strictly larger than the corresponding character in <code>b</code>.</p>
<ul>
<li>For example, <code>"abcd"</code> is lexicographically larger than <code>"abcc"</code> because the first position they differ is at the fourth character, and <code>d</code> is greater than <code>c</code>.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “abcz”, k = 26</p>
<p><strong>Output:</strong> “abda”</p>
<p><strong>Explanation:</strong></p>
<p>The string “abda” is beautiful and lexicographically larger than the string “abcz”.</p>
<p>It can be proven that there is no string that is lexicographically larger than the string “abcz”, beautiful, and lexicographically smaller than the string “abda”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “dc”, k = 4</p>
<p><strong>Output:</strong> ""</p>
<p><strong>Explanation:</strong> It can be proven that there is no string that is lexicographically larger than the string “dc” and is beautiful.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n == s.length <= 10<sup>5</sup></code></li>
<li><code>4 <= k <= 26</code></li>
<li><code>s</code> is a beautiful string.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
smallestBeautifulString
-