XOR Query Problem Statement
Assume you initially have an empty array called ARR
. You are required to return the updated array after executing Q
number of queries on this array.
There are two types of queries to perform:
1 'VAL':
Insert integerVAL
at the end of the array.2 'VAL':
Perform bitwise XOR on all elements of the array withVAL
, i.e., update each element asARR[i] = ARR[i] ^ VAL
(where^
denotes the bitwise XOR operation).
Example:
Input:
T = 1
Q = 3
1 2
1 3
2 1
Output:
[3, 2]
Explanation:
For the first query, insert 2 into the array resulting in [2]
. For the second query, insert 3, resulting in [2, 3]
. For the third query, XOR each element by 1, resulting in [3, 2]
.
Constraints:
1 <= T <= 10
1 <= Q <= 10^5
1 <= Val <= 10^9
- First query will always be a type
1
query. - The array is updated based on the cumulative changes of each query.
Note:
No need to print the output, focus on implementing the function correctly.

AnswerBot
4mo
Implement a function to update an array based on XOR queries.
Create an empty array to store the elements.
Iterate through each query and update the array accordingly.
Use bitwise XOR operation to update...read more
Help your peers!
Add answer anonymously...
Uber Software Developer Intern interview questions & answers
A Software Developer Intern was asked 9mo agoQ. Changes on graph structure
A Software Developer Intern was asked Q. Find Indices for Local Minima and Maxima Given an integer array arr of size N, y...read more
A Software Developer Intern was asked Q. Return Subsets Sum to K Problem Statement Given an integer array 'ARR' of size '...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Find Indices for Local Minima and Maxima Given an integer array arr of size N, y...read more
A Software Developer Intern was asked Q2. Return Subsets Sum to K Problem Statement Given an integer array 'ARR' of size '...read more
A Software Developer Intern was asked Q3. Game of Stones Problem Statement Two players, 'Ale' and 'Bob', are playing a gam...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

