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 integer VAL at the end of the array.
  • 2 'VAL': Perform bitwise XOR on all elements of the array with VAL, i.e., update each element as ARR[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
1y

The problem requires updating an array based on a series of queries, where each query can either insert a value or perform a bitwise XOR operation on all elements.

  • Use a loop to iterate through each qu...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Intern Interview Questions Asked at Texas Instruments

Q. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
Q. Largest Rectangle in Histogram Problem Statement You are given an array/list HEI...read more
Q. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more
Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits