We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Nope, this should work. Note that if you take a ^ a, you will always get 0. Furthermore, if you take a ^ x ^ a, you will always get x. Therefore, all the pairs of numbers will cancel out. For example, if you have n = 9 and A = {4, 9, 95, 93, 57, 4, 57, 93, 9}, then you will effectively by computing the value of 4 ^ 9 ^ 95 ^ 93 ^ 57 ^ 4 ^ 57 ^ 93 ^ 9. It doesn't matter what order you take the xors, so this is equivalent to (4 ^ 4) ^ (9 ^ 9) ^ (95) ^ (93 ^ 93) ^ (57 ^ 57), which is 0 ^ 0 ^ 95 ^ 0 ^ 0, or just 95.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
Nope, this should work. Note that if you take
a ^ a
, you will always get0
. Furthermore, if you takea ^ x ^ a
, you will always getx
. Therefore, all the pairs of numbers will cancel out. For example, if you haven = 9
andA = {4, 9, 95, 93, 57, 4, 57, 93, 9}
, then you will effectively by computing the value of4 ^ 9 ^ 95 ^ 93 ^ 57 ^ 4 ^ 57 ^ 93 ^ 9
. It doesn't matter what order you take the xors, so this is equivalent to(4 ^ 4) ^ (9 ^ 9) ^ (95) ^ (93 ^ 93) ^ (57 ^ 57)
, which is0 ^ 0 ^ 95 ^ 0 ^ 0
, or just95
.