java.lang.Object
g2001_2100.s2048_next_greater_numerically_balanced_number.Solution

public class Solution extends Object
2048 - Next Greater Numerically Balanced Number.<p>Medium</p> <p>An integer <code>x</code> is <strong>numerically balanced</strong> if for every digit <code>d</code> in the number <code>x</code>, there are <strong>exactly</strong> <code>d</code> occurrences of that digit in <code>x</code>.</p> <p>Given an integer <code>n</code>, return <em>the <strong>smallest numerically balanced</strong> number <strong>strictly greater</strong> than</em> <code>n</code><em>.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 1</p> <p><strong>Output:</strong> 22</p> <p><strong>Explanation:</strong></p> <p>22 is numerically balanced since:</p> <ul> <li>The digit 2 occurs 2 times.</li> </ul> <p>It is also the smallest numerically balanced number strictly greater than 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 1000</p> <p><strong>Output:</strong> 1333</p> <p><strong>Explanation:</strong></p> <p>1333 is numerically balanced since:</p> <ul> <li> <p>The digit 1 occurs 1 time.</p> </li> <li> <p>The digit 3 occurs 3 times.</p> </li> </ul> <p>It is also the smallest numerically balanced number strictly greater than 1000. Note that 1022 cannot be the answer because 0 appeared more than 0 times.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 3000</p> <p><strong>Output:</strong> 3133</p> <p><strong>Explanation:</strong></p> <p>3133 is numerically balanced since:</p> <ul> <li> <p>The digit 1 occurs 1 time.</p> </li> <li> <p>The digit 3 occurs 3 times.</p> </li> </ul> <p>It is also the smallest numerically balanced number strictly greater than 3000.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= n <= 10<sup>6</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • nextBeautifulNumber

      public int nextBeautifulNumber(int n)