Problem · Array
Count Even-Digit Numbers
Learn this problemProblem statement
Given an array of positive integers numbers, calculate how many of its elements have an even number of digits.
Note: You are not expected to provide the most optimal solution, but a solution with time complexity not worse than O(numbers.length2) will fit within the execution time limit.
Function
solution(numbers: int[]) → intExamples
Example 1
numbers = [12, 134, 111, 1111, 10]return = 3numbers[0] = 12has2digits, which is an even number.numbers[1] = 134has3digits, which is not an even number.numbers[2] = 111has3digits, which is not an even number.numbers[3] = 1111has4digits, which is an even number.numbers[4] = 10has2digits, which is an even number.
There are 3 elements, numbers[0], numbers[3], and numbers[4], with an even number of digits.
Constraints
1 <= numbers.length <= 10001 <= numbers[i] <= 104