FastPrepCount Subarrays With Given XOR
Problems/Count Subarrays With Given XOR

Count Subarrays With Given XOR

InMobi logoInMobi● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi new grad online assessment. Our version is about 99% the same as the reported InMobi online coding test prompt.

You are given an integer array arr and an integer x.

Return the number of non-empty contiguous subarrays whose bitwise XOR is exactly x.

Function

subarraysXor(arr: int[], x: int) → int

Examples

Example 1

arr = [5,3,8,3,10]x = 8return = 2

The qualifying subarrays are [3, 8, 3] and [8].

Example 2

arr = [5,2,9]x = 7return = 1

Only the subarray [5, 2] has XOR 7.

Example 3

arr = [0,0,0]x = 0return = 6

Every non-empty contiguous subarray has XOR 0, and an array of length 3 has 6 such subarrays.

Constraints

  • 3 <= arr.length <= 5 * 10^4
  • 0 <= arr[i] <= 10^9
  • 0 <= x <= 10^9

More InMobi Online Assessment questions

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
  • Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
  • Minimum Service Cold StartsOA · Seen Oct 2026
  • Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
  • Connected Components with Divisor ThresholdOA · Seen Aug 2026
  • Maximize Impression ValueOA · Seen Aug 2026
  • Supply Path OptimizationOA · Seen Aug 2026
  • Delivery ServiceOA · Seen Jun 2026
  • Shared InterestOA · Seen Jun 2026

Similar questions at other companies

  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Calculate the Sum After Range TogglesBlink Health · OA
  • Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
  • Count Valid Bitwise PairsStripe · OAStripe interview questions
  • Count Zero-Sum FragmentsTesla · OATesla interview questions
  • Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
  • Count Stable Server SubsegmentsScale AI · OAScale AI interview questions
  • Number of Unique Elements After Modifications 🍁Infosys · OAInfosys interview questions
  • Count Paired Subarrays Reaching a TargetZipRecruiter · OAZipRecruiter interview questions
  • Longest Substring with Even OccurrencesDeloitte · OADeloitte interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public int subarraysXor(int[] arr, int x) {
        // write your code here.
    }
}
Checking account…