FastPrepFind the Element With Odd Frequency

Find the Element With Odd Frequency

Zscaler logoZscaler● EasyINTERNPHONE SCREEN
Learn

Problem statement

Given a nonempty integer array values, exactly one distinct value occurs an odd number of times. Every other distinct value occurs an even number of times.

Return the value whose frequency is odd.

Function

findOddFrequencyElement(values: int[]) → int

Examples

Example 1

values = [2,3,2,3,3]return = 3

Value 2 appears twice, while 3 appears three times.

Example 2

values = [7]return = 7

The only value appears once, which is odd.

Example 3

values = [10,20,10,20,10,20,10]return = 20

Value 10 appears four times and 20 appears three times.

Constraints

  • 1 <= values.length <= 200000
  • -10^9 <= values[i] <= 10^9
  • Exactly one distinct value has odd frequency; every other distinct value has even frequency.

More Zscaler problems

See Zscaler hiring insights
public int findOddFrequencyElement(int[] values) {
  // write your code here
}
values[2,3,2,3,3]
expected3
Checking account…