2663. Lexicographically Smallest Beautiful String Hard

@problem@discussion
#String#Greedy



1/**
2 * [2663] Lexicographically Smallest Beautiful String
3 *
4 * A string is beautiful if:
5 * 
6 * 	It consists of the first k letters of the English lowercase alphabet.
7 * 	It does not contain any substring of length 2 or more which is a palindrome.
8 * 
9 * You are given a beautiful string s of length n and a positive integer k.
10 * Return the lexicographically smallest string of length n, which is larger than s and is beautiful. If there is no such string, return an empty string.
11 * A string a is lexicographically larger than a string b (of the same length) if in the first position where a and b differ, a has a character strictly larger than the corresponding character in b.
12 * 
13 * 	For example, "abcd" is lexicographically larger than "abcc" because the first position they differ is at the fourth character, and d is greater than c.
14 * 
15 *  
16 * <strong class="example">Example 1:
17 * 
18 * Input: s = "abcz", k = 26
19 * Output: "abda"
20 * Explanation: The string "abda" is beautiful and lexicographically larger than the string "abcz".
21 * 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".
22 * 
23 * <strong class="example">Example 2:
24 * 
25 * Input: s = "dc", k = 4
26 * Output: ""
27 * Explanation: It can be proven that there is no string that is lexicographically larger than the string "dc" and is beautiful.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= n == s.length <= 10^5
33 * 	4 <= k <= 26
34 * 	s is a beautiful string.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/lexicographically-smallest-beautiful-string/
40// discuss: https://leetcode.com/problems/lexicographically-smallest-beautiful-string/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn smallest_beautiful_string(s: String, k: i32) -> String {
46        String::new()
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2663() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.