Introduction
You just can't go to a technical interview without preparing the hot topic, i.e., XOR Bitwise operator. Interviews after the interview, we see questions of XOR being asked. Thus it's important to master such a topic. So to help you, your Ninja is here, and today, we will see one such question, i.e., XOR and Lucky Number.
Understanding the Problem
We have been given an array 'ARR' of length 'N' and a favorite number 'K.' Now there are 'M' queries that we have to answer. In each query, we are given a pair [L, R], and we have to return the number of pairs of integers' i' and 'j' such that L<i<j<R and the XOR value of the numbers in this range s equal to 'K.'
Let's understand this by the following example.
Example
Input
ARR = [1, 2, 1, 1, 0, 3]
Queries = [1,6], [3,5]
K = 3
Output
7
0
Explanation:
We can see that in the first query, the XOR value of numbers (1,2), (1,2,1,1), (1,2,1,1,0), (2,1), (1,1,0,3), (0,3), and (3), is equal to 'K'; thus, our answer for the first query is 7.
Whereas in the second query, the XOR value of any sequence of indexes does not match the value of 'K'; thus, the answer for the second query is 0.
Check out Euclid GCD Algorithm




