Loading practice problems…
Loading your practice workspace…
Loading code editor…
12 / 29
Sign in
Algorithms/Linear Search

Find Numbers with Even Number of Digits

easy15 min

Given an array of positive integers, return how many values contain an even number of decimal digits.

Inspect each value and count only those with 2, 4, 6, or another even number of digits.

Example 1

Inputnums = [12, 345, 2, 6, 7896]

Output2

12 has two digits and 7896 has four. The other values have odd digit counts, so the result is 2.

Example 2

Inputnums = [555, 901, 482, 1771]

Output1

1771 has four digits. Each of the other numbers has three, so only one number qualifies.

Constraints

  • 1 ≤ nums.length ≤ 500
  • 1 ≤ nums[i] ≤ 100,000
Linear SearchArrays