Count Subarrays With Given XOR
Updated
Problem statement
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) → intExamples
Example 1
arr = [5,3,8,3,10]x = 8return = 2The qualifying subarrays are [3, 8, 3] and [8].
Example 2
arr = [5,2,9]x = 7return = 1Only the subarray [5, 2] has XOR 7.
Example 3
arr = [0,0,0]x = 0return = 6Every non-empty contiguous subarray has XOR 0, and an array of length 3 has 6 such subarrays.
Constraints
3 <= arr.length <= 5 * 10^40 <= arr[i] <= 10^90 <= 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