Class Solution
-
- All Implemented Interfaces:
public final class Solution2663 - Lexicographically Smallest Beautiful String.
Hard
A string is beautiful if:
It consists of the first
kletters of the English lowercase alphabet.It does not contain any substring of length
2or more which is a palindrome.
You are given a beautiful string
sof lengthnand a positive integerk.Return the lexicographically smallest string of length
n, which is larger thansand is beautiful. If there is no such string, return an empty string.A string
ais lexicographically larger than a stringb(of the same length) if in the first position whereaandbdiffer,ahas a character strictly larger than the corresponding character inb.For example,
"abcd"is lexicographically larger than"abcc"because the first position they differ is at the fourth character, anddis greater thanc.
Example 1:
Input: s = "abcz", k = 26
Output: "abda"
Explanation:
The string "abda" is beautiful and lexicographically larger than the string "abcz".
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".
Example 2:
Input: s = "dc", k = 4
Output: ""
Explanation: It can be proven that there is no string that is lexicographically larger than the string "dc" and is beautiful.
Constraints:
<code>1 <= n == s.length <= 10<sup>5</sup></code>
4 <= k <= 26sis a beautiful string.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final StringsmallestBeautifulString(String s, Integer k)-
-
Method Detail
-
smallestBeautifulString
final String smallestBeautifulString(String s, Integer k)
-
-
-
-