Ctrl K

Equal Half Digit Sums

Easy
Call a number balanced if it has an even number of digits and the digits of its left half add up to the same total as the digits of its right half. For example, 1423 is balanced (1 + 4 = 2 + 3), while 121 is not, since it has an odd number of digits. Given low and high, return how many balanced numbers lie between low and high, inclusive.
Example 1
low=40, high=70 → 3

A two-digit number is balanced only when both digits match: 44, 55 and 66.

Example 2
low=2310, high=2330 → 2

The first two digits add up to 5. That fits 2314 (1 + 4), 2323 (2 + 3) and 2330 (3 + 0).

Example 3
low=100, high=999 → 0

Three-digit numbers have an odd number of digits, so none are balanced.

Constraints
  • 1 ≤ low ≤ high ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNearest Short Hex Color EasyXOR of Every Subset EasyWhole-Number Right Triangles EasyA Trio of Divisors EasyCount Shared Divisors Easy
loading Python…
Input
low=40, high=70
Expected
3

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