1,962 views
0 votes
0 votes

You are given a list of 5 integers and these integers are in the range from 1 to 6. There are no duplicates in list. One of the integers is missing in the list. Which of the following expression would give the missing number?

^ is bitwise XOR operator.

~ is bitwise NOT operator.

Let elements of list can be accessed as list[0], list[1], list[2], list[3], list[4]

(a) list[0] ^ list[1] ^ list[2] ^ list[3] ^ list[4]

(b) list[0] ^ list[1] ^ list[2] ^ list[3] ^ list[4] ^ 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6

(c) list[0] ^ list[1] ^ list[2] ^ list[3] ^ list[4] ^ 1 ^ 2 ^ 3 ^ 4 ^ 5

(d) ~(list[0] ^ list[1] ^ list[2] ^ list[3] ^ list[4])

1 Answer

0 votes
0 votes
$x$ ^ $x$  $=0$

The value which will come after applying the operation of option $(b)$ is the value which is not in the $array$. So, now we know all the values that are in the array, and we can find the missing value.

For example :

Let the values of the array we know are $1,3,5,6$,  and let $4$ be the missing value.

When we apply option $(b)$ we get value $6$, so we know the values in the array are $1,3,4,5,6$, so we found the missing value in the array $i.e.\,4$