Skip to content

2843. Count Symmetric Integers #1546

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to count the number of symmetric integers within a given range [low, high]. A symmetric integer is defined as a number with an even number of digits where the sum of the first half of the digits is equal to the sum of the second half of the digits.

Approach

  1. Iterate through the range: Check each number from low to high inclusive.
  2. Check for even digit count: Convert each number to a string to determine its length. If the length is odd, the number cannot be symmetric, so we skip it.
  3. Split and sum digits: For numbers with even digits, split the digits into two halves. Calculate the sum of the digits in the first half and the sum of the digits in the second half.
  4. Compare sums: If the …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Apr 11, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Apr 11, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants