Next Greater Numerically Balanced Number
Problem statement
A positive integer is numerically balanced when every digit d that appears in it occurs exactly d times.
Given an integer n, return the smallest numerically balanced integer that is strictly greater than n.
Function
nextBeautifulNumber(n: int) → intExamples
Example 1
n = 1return = 22The digit 2 occurs exactly twice, and 22 is the smallest balanced value greater than 1.
Example 2
n = 1000return = 1333Digit 1 appears once and digit 3 appears three times.
Example 3
n = 3000return = 31333133 is balanced and is the first balanced value after 3000.
Constraints
0 <= n <= 1000000.