3646. Next Special Palindrome Number Hard

@problem@discussion
#Backtracking#Bit Manipulation



1/**
2 * [3646] Next Special Palindrome Number
3 *
4 * You are given an integer n.
5 * A number is called special if:
6 * 
7 * 	It is a <span data-keyword="palindrome-integer">palindrome</span>.
8 * 	Every digit k in the number appears exactly k times.
9 * 
10 * Return the smallest special number strictly greater than n.
11 *  
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">n = 2</span>
15 * Output: <span class="example-io">22</span>
16 * Explanation:
17 * 22 is the smallest special number greater than 2, as it is a palindrome and the digit 2 appears exactly 2 times.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">n = 33</span>
22 * Output: <span class="example-io">212</span>
23 * Explanation:
24 * 212 is the smallest special number greater than 33, as it is a palindrome and the digits 1 and 2 appear exactly 1 and 2 times respectively.<br />
25 *  
26 * </div>
27 *  
28 * Constraints:
29 * 
30 * 	0 <= n <= 10^15
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/next-special-palindrome-number/
36// discuss: https://leetcode.com/problems/next-special-palindrome-number/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn special_palindrome(n: i64) -> i64 {
42        
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_3646() {
54    }
55}
56

Back
© 2026 bowen.ge All Rights Reserved.