3734. Lexicographically Smallest Palindromic Permutation Greater Than Target Hard

@problem@discussion
#Two Pointers#String#Enumeration



1/**
2 * [3734] Lexicographically Smallest Palindromic Permutation Greater Than Target
3 *
4 * You are given two strings s and target, each of length n, consisting of lowercase English letters.
5 * Return the <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> string that is both a <span data-keyword="palindrome-string">palindromic</span> <span data-keyword="permutation">permutation</span> of s and strictly greater than target. If no such permutation exists, return an empty string.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">s = "baba", target = "abba"</span>
10 * Output: <span class="example-io">"baab"</span>
11 * Explanation:
12 * 
13 * 	The palindromic permutations of s (in lexicographical order) are "abba" and "baab".
14 * 	The lexicographically smallest permutation that is strictly greater than target is "baab".
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">s = "baba", target = "bbaa"</span>
19 * Output: <span class="example-io">""</span>
20 * Explanation:
21 * 
22 * 	The palindromic permutations of s (in lexicographical order) are "abba" and "baab".
23 * 	None of them is lexicographically strictly greater than target. Therefore, the answer is "".
24 * </div>
25 * <strong class="example">Example 3:
26 * <div class="example-block">
27 * Input: <span class="example-io">s = "abc", target = "abb"</span>
28 * Output: <span class="example-io">""</span>
29 * Explanation:
30 * s has no palindromic permutations. Therefore, the answer is "".
31 * </div>
32 * <strong class="example">Example 4:
33 * <div class="example-block">
34 * Input: <span class="example-io">s = "aac", target = "abb"</span>
35 * Output: <span class="example-io">"aca"</span>
36 * Explanation:
37 * 
38 * 	The only palindromic permutation of s is "aca".
39 * 	"aca" is strictly greater than target. Therefore, the answer is "aca".
40 * </div>
41 *  
42 * Constraints:
43 * 
44 * 	1 <= n == s.length == target.length <= 300
45 * 	s and target consist of only lowercase English letters.
46 * 
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/lexicographically-smallest-palindromic-permutation-greater-than-target/
51// discuss: https://leetcode.com/problems/lexicographically-smallest-palindromic-permutation-greater-than-target/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56    pub fn lex_palindromic_permutation(s: String, target: String) -> String {
57        String::new()
58    }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65    use super::*;
66
67    #[test]
68    fn test_3734() {
69    }
70}
71

Back
© 2026 bowen.ge All Rights Reserved.