2048. Next Greater Numerically Balanced Number Medium

@problem@discussion
#Math#Backtracking#Enumeration



1/**
2 * [2048] Next Greater Numerically Balanced Number
3 *
4 * An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x.
5 * Given an integer n, return the smallest numerically balanced number strictly greater than n.
6 *  
7 * Example 1:
8 * 
9 * Input: n = 1
10 * Output: 22
11 * Explanation: 
12 * 22 is numerically balanced since:
13 * - The digit 2 occurs 2 times. 
14 * It is also the smallest numerically balanced number strictly greater than 1.
15 * 
16 * Example 2:
17 * 
18 * Input: n = 1000
19 * Output: 1333
20 * Explanation: 
21 * 1333 is numerically balanced since:
22 * - The digit 1 occurs 1 time.
23 * - The digit 3 occurs 3 times. 
24 * It is also the smallest numerically balanced number strictly greater than 1000.
25 * Note that 1022 cannot be the answer because 0 appeared more than 0 times.
26 * 
27 * Example 3:
28 * 
29 * Input: n = 3000
30 * Output: 3133
31 * Explanation: 
32 * 3133 is numerically balanced since:
33 * - The digit 1 occurs 1 time.
34 * - The digit 3 occurs 3 times.
35 * It is also the smallest numerically balanced number strictly greater than 3000.
36 * 
37 *  
38 * Constraints:
39 * 
40 * 	0 <= n <= 10^6
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/next-greater-numerically-balanced-number/
46// discuss: https://leetcode.com/problems/next-greater-numerically-balanced-number/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn next_beautiful_number(n: i32) -> i32 {
52        0
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_2048() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.