Count Subarrays with Given XOR Problem Statement

You are given an array of integers ARR and an integer X. Your task is to determine the number of subarrays of ARR whose bitwise XOR is equal to X.

Example:

Input:
The first line contains a single integer ‘T’, the number of test cases. Each test case comprises:
1. A line containing two integers N and X.
2. A line with N space-separated integers, the elements of ARR.
Output:
For each test case, output the count of subarrays whose XOR is equal to X, each on a new line.

Constraints:

  • 1 <= T <= 10
  • 3 <= N <= 5 * 10^4
  • 0 <= X <= 10^9
  • 0 <= ARR[i] <= 10^9

Note:

A subarray ‘B’ of an array ‘A’ is derived by deleting elements from the start and/or the end of ‘A’. You need not print anything; the core function should return the results.

AnswerBot
4mo

Count the number of subarrays in an array whose XOR is equal to a given value.

  • Iterate through the array and keep track of XOR values and their frequencies using a hashmap.

  • For each element in the array...read more

Help your peers!
Select
Add answer anonymously...

Think Future Technologies Software Developer interview questions & answers

A Software Developer was asked Q. Can you provide an example of how to use pointers in C/C++ and discuss different...read more
A Software Developer was asked Q. Pair Sum Problem Statement You are given an integer array 'ARR' of size 'N' and ...read more
A Software Developer was asked Q. Distinct Characters Problem Statement Given a string STR, return all possible no...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Can you provide an example of how to use pointers in C/C++ and discuss different...read more
A Software Developer was asked Q2. Pair Sum Problem Statement You are given an integer array 'ARR' of size 'N' and ...read more
A Software Developer was asked Q3. Distinct Characters Problem Statement Given a string STR, return all possible no...read more
Think Future Technologies Software Developer 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