Class Solution
java.lang.Object
g1301_1400.s1310_xor_queries_of_a_subarray.Solution
1310 - XOR Queries of a Subarray.<p>Medium</p>
<p>You are given an array <code>arr</code> of positive integers. You are also given the array <code>queries</code> where <code>queries[i] = [left<sub>i,</sub> right<sub>i</sub>]</code>.</p>
<p>For each query <code>i</code> compute the <strong>XOR</strong> of elements from <code>left<sub>i</sub></code> to <code>right<sub>i</sub></code> (that is, <code>arr[left<sub>i</sub>] XOR arr[left<sub>i</sub> + 1] XOR … XOR arr[right<sub>i</sub>]</code> ).</p>
<p>Return an array <code>answer</code> where <code>answer[i]</code> is the answer to the <code>i<sup>th</sup></code> query.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]</p>
<p><strong>Output:</strong> [2,7,14,8]</p>
<p><strong>Explanation:</strong></p>
<p>The binary representation of the elements in the array are:</p>
<p>1 = 0001</p>
<p>3 = 0011</p>
<p>4 = 0100</p>
<p>8 = 1000</p>
<p>The XOR values for queries are:</p>
<p>[0,1] = 1 xor 3 = 2</p>
<p>[1,2] = 3 xor 4 = 7</p>
<p>[0,3] = 1 xor 3 xor 4 xor 8 = 14</p>
<p>[3,3] = 8</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]</p>
<p><strong>Output:</strong> [8,0,4,4]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= arr.length, queries.length <= 3 * 10<sup>4</sup></code></li>
<li><code>1 <= arr[i] <= 10<sup>9</sup></code></li>
<li><code>queries[i].length == 2</code></li>
<li><code>0 <= left<sub>i</sub> <= right<sub>i</sub> < arr.length</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
xorQueries
public int[] xorQueries(int[] a, int[][] queries)
-