Problem · Array

Count Elements with Odd Number of Zeroes

Learn this problem
EasyUberOA
See Uber hiring insights

Problem statement

Note - See source image for the original statement :)

You have an array of non-negative integers, and your task is to figure out how many of these numbers contain an odd number of zeros in their digits. For instance, given the array [4, 50, 100, 65, 2000, 700, 1, 10], the answer would be 3, since the numbers 50, 2000, and 10 each have an odd count of the digit 0. Don't worry about finding the most efficient solution; just ensure that your approach works within a reasonable time frame.

Function

countElements(a: int[]) → int

Examples

Example 1

a = [20, 11, 10, 10070, 7]return = 3
In the array, the elements a[1] = 11 and a[4] = 7 don't contain the digit 0, so they don't count (since zero occurrences are considered even). However, the elements a[0] = 20 and a[2] = 10 each have one occurrence of the digit 0, which is odd, so they do count. Additionally, a[3] = 10070 has three zeros, which is also an odd number, so this element counts as well.

Constraints

🥭

More Uber problems

drafts saved locally
public int countElements(int[] a) {
  // write your code here
}
a[20, 11, 10, 10070, 7]
expected3
checking account