This post is completed by 1 user

  • 1
Add to List
Beginner

141. Find the Single Occurrence Element in an Array (Odd One Out)

Objective: In an array of integers, each element occurs an even number of times except for one element, which occurs an odd number of times. Determine and retrieve that particular number.

Example:

int[] A = { 1, 4, 2, 2, 3, 3, 4, 1, 5, 5, 5, 6, 7, 6, 6, 7, 6 };
Element appearing odd number of times: 5

Approach:

we know that A XOR A = 0 so numbers appearing an even number of times will be canceled out and the remaining elements will be the number which is appearing an odd number of times.

Element appearing add number of times: 5