Ctrl K

Balanced Parity Number

Medium
Call an integer **balanced** if its decimal form has as many even digits as odd ones. For example, 1234 and 50 are balanced, while 135 and 2468 are not. You are given a positive integer start. Return the smallest balanced number that is greater than or equal to start.
Example 1
start=7 → 10

A one-digit number can never be balanced. The first fit is 10: one odd digit (1) and one even digit (0).

Example 2
start=4521 → 4521

4521 has two even digits (4, 2) and two odd ones (5, 1), so it is already balanced.

Example 3
start=888 → 1001

No three-digit number works, and the first balanced four-digit number is 1001.

Constraints
  • 1 ≤ start ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumShuffle the Digits Into a Power of Two MediumSums of Two Powers MediumA Multiple Spelled With Two Digits MediumMicrowave Keypad Effort Medium
loading Python…
Input
start=7
Expected
10

Run checks the first 3 tests in your browser. Submit checks all 65 tests on the server, hidden ones included.