We can find out the lone wolf's solumatesheep value in a single query: 0 1 N as the other numbers will be cancelled out in the XOR. Now we have a sorted array, and we can access the value of any index i with the query : 0 i i. We can do a simple binary search to find the lone wolf's position. So total query won't be more than 1 + log2(100000).