Friday, May 21, 2010

Element which has no duplicate entries

Given an array of numbers where each number has a duplicate in the array except one number, write a program to return the lone number.

For eg: if the array is 1,8,5,8,1,3,5 then your program should return 3.




This can be achieved by XORing all the elements in the array. The final value in the variable after XORing is the result

No comments:

Post a Comment