30. Even-Length Numbers

A printing shop numbers its jobs with positive whole numbers. For a special promotion, only jobs whose job number has an even number of digits (for example 12 or 4096, but not 345) receive a discount sticker.

Write a method countEvenDigitNumbers that takes the array nums of job numbers and returns how many of them have an even number of digits.

Example 1

Input:
nums = [12,345,2,6,7896]
Output:
2
Explanation:

12 has 2 digits and 7896 has 4 digits; 345, 2 and 6 have an odd number of digits. The answer is 2.

Example 2

Input:
nums = [555,901,482,1771]
Output:
1
Explanation:

Only 1771 has an even number of digits (4).

Constraints

1 ≤ nums.length ≤ 1000

1 ≤ nums[i] ≤ 105

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(n)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…