Count Numbers with an Even Number of Digits
ByteDanceSoftware Engineer · Online AssessmentLast updated
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.
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]returns3.[7, 10000]returns0.
Edge Cases
- A one-digit number is not counted.
- The upper-bound value
10000has five digits. - Repeated values count separately.
Hints
Hint 1
Count decimal places: Converting to a decimal string is sufficient under these bounds; repeated division by ten is another valid approach.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.