Magicsheet logo

Count Symmetric Integers

Easy
25%
Updated 8/1/2025

Count Symmetric Integers

What is this problem about?

The Count Symmetric Integers coding problem asks you to count how many integers in a given range [low,high][low, high] are "symmetric." An integer is symmetric if it has an even number of digits 2n2n, and the sum of its first nn digits equals the sum of its last nn digits.

For example, 1212 is symmetric because 1+2=1+21+2 = 1+2. 123 is not symmetric because it has an odd number of digits. 1230 is symmetric because 1+2=3+01+2 = 3+0.

Why is this asked in interviews?

This problem is popular at companies like Apple and Meta for entry-level roles. It tests basic enumeration interview pattern skills and string/math manipulation. It evaluates whether a candidate can handle range constraints and implement logic to split a number and compare its parts. It also checks if you remember to filter out numbers with an odd number of digits.

Algorithmic pattern used

This is an Enumeration and String Manipulation/Math problem.

  1. Loop through every integer ii from low to high.
  2. Convert ii to a string to easily count digits and access them.
  3. Check if the string length is even. If not, skip.
  4. Split the string into two halves.
  5. Sum the numerical values of the digits in the first half and the second half.
  6. If the sums are equal, increment your result.

Example explanation

Range: [10,100][10, 100]

  1. Integers with even digits: 10, 11, ..., 99. (All have 2 digits).
  2. Check 11: 1 = 1. (Symmetric)
  3. Check 12: 1 e e 2. (Not symmetric)
  4. Check 22: 2 = 2. (Symmetric)
  5. There are 9 symmetric integers in this range (11, 22, 33, 44, 55, 66, 77, 88, 99).

Range: [1200,1230][1200, 1230]

  1. Check 1203: 1+2=0+31+2 = 0+3 (3=33=3). (Symmetric)
  2. Check 1212: 1+2=1+21+2 = 1+2 (3=33=3). (Symmetric)
  3. Check 1221: 1+2=2+11+2 = 2+1 (3=33=3). (Symmetric)

Common mistakes candidates make

  • Ignoring odd-length numbers: Forgetting that symmetry is only defined for numbers with an even number of digits in this problem.
  • Inefficient summation: Converting to string and then back to integer repeatedly can be slow, though for small ranges it’s acceptable.
  • Boundary errors: Missing the low or high values in the loop.

Interview preparation tip

When working with properties of numbers (like digit sums), practice both the string conversion method and the mathematical method (using / 10 and % 10). The mathematical approach is often preferred in high-performance or low-memory environments.

Similar Questions