Find a Number occurring odd number of times in a Given array

Objective: Given a array of integers, in which every elements occurs even number of times except one number which occurs add number of times. Find out that number.


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


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



Element appearing add number of times: 5

Top Companies Interview Questions..-

Google Microsoft Amazon Facebook more..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.

You may also like...

2 Responses

  1. Varun Bhandari says:

    Code Does not work for this input : {2, 7, 5, 4, 5, 2, 4, 3, 5, 2, 4, 4, 2, 7, 4, 4};
    Returns ‘6’ which is not even in the array.

    • tutorialhorizon says:

      Because your input has two numbers 3 and 5 which occurs odd number of times. Objec­tive of problem is ” Given a array of inte­gers, in which every ele­ments occurs even num­ber of times except one num­ber which occurs add num­ber of times”

Leave a Reply to Varun Bhandari Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: