recategorized by
296 views
1 votes
1 votes

recategorized by

1 Answer

2 votes
2 votes
Ans is B.

First understand this, for any number a, a^a= 0,  and 0^a= a. Also ^ is associative. i.e. a^b^c = a^c^b.. you can write in any order

So what will be a^a^a^a ?.. Yes it will be 0.. and what will be a^a^a?.. it will be a. Observe how xor works.. even number of same term will result in 0, and odd number of same term when xored will give that term.

So to find which number is NOT present in list, we will do xor of all elements in array with all possible elements

here if we do .. list[0]^list[1]^list[2]^list[3]^list[4]^1^2^3^4^5^6,

then, out of 1 to 6, any number which comes twice will be cancelled and only the number not present in array will not form a pair

example, if array list is 4, 2, 5 ,1 ,6

then list[0]^list[1]^list[2]^list[3]^list[4]^1^2^3^4^5^6 = 4^2^5^1^6^1^2^3^4^5^6 = 3... observe here 1 appears twice, hence 1^1=0 similarly 2,4,5,6 all appear twice, and they all cancel each other. Only 3 remains, bcoz it appears only once.

Related questions