Match an XOR-Adjusted Sum
Updated
Problem statement
Determine whether there is an integer x such that 0 <= x < 2^bitWidth and the sum of values[i] XOR x over every array position equals target.
Use the same x for every position. Return true if any such value exists, and false otherwise.
For this exercise, assume the bit width is supplied explicitly, all values fit in that width, and only existence is required. The sum uses signed 64-bit arithmetic.
Function
hasXorAdjustedSum(values: int[], target: long, bitWidth: int) → booleanExamples
Example 1
values = [1,2]target = 3bitWidth = 2return = trueChoose x = 0. The XOR values stay 1 and 2, whose sum is 3.
Example 2
values = [0,0]target = 1bitWidth = 2return = falseBoth XOR values equal x, so their sum is 2*x and cannot be the odd target 1.
Example 3
values = [1]target = 6bitWidth = 3return = trueChoose x = 7, which fits in three bits. Then 1 XOR 7 = 6.
Constraints
1 <= values.length <= 60.1 <= bitWidth <= 30.0 <= values[i] <= 1073741823, and every value is smaller than2^bitWidth.0 <= target <= 1000000000000.
More Squarepoint Capital interview questions
- Evaluating Circuit ExpressionsOA · Seen Jul 2026
- Maximize Palindromic WordsOA · Seen Oct 2025
- Minimize the Sum with Ceiling HalvesOA · Seen Oct 2025
- Longest Increasing Subsequence from Two ArraysOA · Seen Oct 2025
- Resolve Overlapping Price RangesOA · Seen Dec 2024
- Empty ShelfOA · Seen Sep 2024
- Suggested ProductsOA · Seen Sep 2024
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
- Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
- Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Minimum Operations To Reduce To ZeroUber · OAUber interview questions
- Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Submask Sum QueriesIntuit · OAIntuit interview questions
- Distinct Bitwise-OR Scores of Increasing SubsequencesWalmart · OAWalmart interview questions
- Profitable Currency Exchange CycleOptiver · OAOptiver interview questions
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions