Problem · Array

Count Even-Digit Numbers

Learn this problem
EasyTiktok logoTiktokOA
See Tiktok hiring insights

Problem 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[]) → int

Examples

Example 1

numbers = [12, 134, 111, 1111, 10]return = 3
  • numbers[0] = 12 has 2 digits, which is an even number.
  • numbers[1] = 134 has 3 digits, which is not an even number.
  • numbers[2] = 111 has 3 digits, which is not an even number.
  • numbers[3] = 1111 has 4 digits, which is an even number.
  • numbers[4] = 10 has 2 digits, 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 <= 1000
  • 1 <= numbers[i] <= 104

More Tiktok problems

drafts saved locally
public int solution(int[] numbers) {
  // write your code here
}
numbers[12, 134, 111, 1111, 10]
expected3
checking account