3518. Smallest Palindromic Rearrangement II Hard

@problem@discussion
#Hash Table#Math#String#Combinatorics#Counting



1/**
2 * [3518] Smallest Palindromic Rearrangement II
3 *
4 * <p data-end="332" data-start="99">You are given a <span data-keyword="palindrome-string">palindromic</span> string s and an integer k.
5 * Return the k-th <span data-keyword="lexicographically-smaller-string">lexicographically smallest</span> palindromic <span data-keyword="permutation-string">permutation</span> of s. If there are fewer than k distinct palindromic permutations, return an empty string.
6 * Note: Different rearrangements that yield the same palindromic string are considered identical and are counted once.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">s = "abba", k = 2</span>
11 * Output: <span class="example-io">"baab"</span>
12 * Explanation:
13 * 
14 * 	The two distinct palindromic rearrangements of "abba" are "abba" and "baab".
15 * 	Lexicographically, "abba" comes before "baab". Since k = 2, the output is "baab".
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">s = "aa", k = 2</span>
20 * Output: <span class="example-io">""</span>
21 * Explanation:
22 * 
23 * 	There is only one palindromic rearrangement: <code data-end="1112" data-start="1106">"aa".
24 * 	The output is an empty string since k = 2 exceeds the number of possible rearrangements.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">s = "bacab", k = 1</span>
29 * Output: <span class="example-io">"abcba"</span>
30 * Explanation:
31 * 
32 * 	The two distinct palindromic rearrangements of "bacab" are "abcba" and "bacab".
33 * 	Lexicographically, "abcba" comes before "bacab". Since k = 1, the output is "abcba".
34 * </div>
35 *  
36 * Constraints:
37 * 
38 * 	1 <= s.length <= 10^4
39 * 	s consists of lowercase English letters.
40 * 	s is guaranteed to be palindromic.
41 * 	1 <= k <= 10^6
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/smallest-palindromic-rearrangement-ii/
47// discuss: https://leetcode.com/problems/smallest-palindromic-rearrangement-ii/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn smallest_palindrome(s: String, k: i32) -> String {
53        String::new()
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_3518() {
65    }
66}
67

Back
© 2026 bowen.ge All Rights Reserved.