Count Symmetric Integers - Problem
You are given two positive integers low and high. An integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x.
Numbers with an odd number of digits are never symmetric.
Return the number of symmetric integers in the range [low, high].
Input & Output
Example 1 — Small Range
$
Input:
low = 1, high = 100
›
Output:
9
💡 Note:
Symmetric numbers: 11 (1=1), 22 (2=2), 33 (3=3), 44 (4=4), 55 (5=5), 66 (6=6), 77 (7=7), 88 (8=8), 99 (9=9). All single digits and odd-length numbers are not symmetric.
Example 2 — Four Digit Range
$
Input:
low = 1200, high = 1230
›
Output:
1
💡 Note:
Only 1221 is symmetric in this range: left sum = 1+2 = 3, right sum = 2+1 = 3. Numbers like 1234 have left sum = 1+2 = 3, right sum = 3+4 = 7.
Example 3 — No Symmetric Numbers
$
Input:
low = 1, high = 10
›
Output:
0
💡 Note:
No symmetric numbers exist. Single digit numbers (1-9) have odd length, and 10 has left sum = 1, right sum = 0.
Constraints
- 1 ≤ low ≤ high ≤ 109
- Numbers with odd digits are never symmetric
- Only even-length numbers can be symmetric
Visualization
Tap to expand
Understanding the Visualization
1
Input Range
Given range [1, 100] to check for symmetric numbers
2
Check Symmetry
Split even-length numbers and compare digit sums
3
Count Results
Count numbers where left sum = right sum
Key Takeaway
🎯 Key Insight: Only even-length numbers can be symmetric - split in half and compare digit sums
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code