12 Sept 2026Go / Python / TypeScriptEasy

Find Numbers with Even Number of Digits

Count the integers whose decimal representation contains an even number of digits.

Convert each positive integer to its decimal representation, test whether its length is even, and count the matches.

complexity

O(n * d) time, where d is the maximum digit count, and O(1) auxiliary space.

solution files

  • Go find-numbers-with-even-number-of-digits/solution.go
  • Python find-numbers-with-even-number-of-digits/solution.py
  • TypeScript find-numbers-with-even-number-of-digits/solution.ts

Solution files

Gofind-numbers-with-even-number-of-digits/solution.go
package main

func findNumbers(nums []int) int {
	count := 0
	for _, number := range nums {
		digits := 0
		for value := number; value > 0; value /= 10 {
			digits++
		}
		if digits%2 == 0 {
			count++
		}
	}
	return count
}
Pythonfind-numbers-with-even-number-of-digits/solution.py
class Solution:
    def findNumbers(self, nums: list[int]) -> int:
        return sum(len(str(number)) % class="syntax-number">2 == class="syntax-number">0 for number in nums)
TypeScriptfind-numbers-with-even-number-of-digits/solution.ts
function findNumbers(nums: number[]): number {
  return nums.reduce(
    (count, number) => count + (String(number).length % class="syntax-number">2 === class="syntax-number">0 ? class="syntax-number">1 : class="syntax-number">0),
    class="syntax-number">0,
  );
}