Quick Overview

Count how many positive integers in an array have an even number of decimal digits. Respect ordinary representations without leading zeroes, count repeated values independently, and handle boundaries such as 10 and 10000 correctly.

Count Numbers with an Even Number of Digits

Company: ByteDance

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

## Problem Given an array of positive integers, count how many elements have an even number of decimal digits. ### Function Contract Implement `count_even_digit_numbers(numbers) -> int`. ### Constraints - `1 <= len(numbers) <= 1000`. - `1 <= numbers[i] <= 10000`. - Use the ordinary base-10 representation without leading zeroes. ### Examples - `[12, 134, 111, 1111, 10]` returns `3`. - `[7, 10000]` returns `0`. ```hint Count decimal places Converting to a decimal string is sufficient under these bounds; repeated division by ten is another valid approach. ``` ### Edge Cases - A one-digit number is not counted. - The upper-bound value `10000` has five digits. - Repeated values count separately.

Overview: Count how many positive integers in an array have an even number of decimal digits. Respect ordinary representations without leading zeroes, count repeated values independently, and handle boundaries such as 10 and 10000 correctly.

Read the full ByteDance Software Engineer interview experience this question came from

Given an array of positive integers, return how many elements have an even number of digits in their ordinary base-10 representation without leading zeroes. Repeated values count separately.

Constraints

  • 1 <= len(numbers) <= 1000.
  • 1 <= numbers[i] <= 10000.
  • Use the ordinary base-10 representation without leading zeroes.
  • Repeated values count separately.

Examples

Input: ([12, 134, 111, 1111, 10],)

Expected Output: 3

Explanation: This is the first source example; 12, 1111, and 10 have even digit counts.

Input: ([7, 10000],)

Expected Output: 0

Explanation: This is the second source example; one and five digits are both odd.

Hints

  1. Count decimal places by converting to a decimal string or repeatedly dividing by ten.

Loading coding console...

Show the approach

Approach

For each positive number, repeatedly divide by ten and count how many divisions are needed to reach zero. This is exactly its number of decimal digits. Increment the answer when that count is even. Processing elements independently naturally preserves multiplicity.

Time complexity:
O(n d), where d is at most 5 under the stated bounds.
Space complexity:
O(1) auxiliary space.