Is there some trick? Because I feel like its trial and error. I saw one question where they asked us to find the missing number in the range of 1 to n, I had no idea how to do it with xor. The solution was to first find the xor of all elements from 1 to n, then the xor of the elements that we were given and then the xor of these both.
How to come to this solution? Because I feel like this solution was found by trial and error. I don't even get how to approach these problems. What do I need to know before solving such problems? Is there some property that I don't know?