← All questions
Coding
Medium: Subarray with a given XOR
Asked at
Boston Consulting Group
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Maintain XOR prefix through current index
- 02Derive needed earlier prefix as prefix xor target
- 03Count matching prefixes in a map
- 04Seed prefix zero with frequency one
- 05Insert current prefix after counting
Reference answer
Then expect these follow-ups
How would you count subarrays with sum k instead?
Tests: follow-up reasoning
Why can the result exceed 32-bit range?
Tests: correctness reasoning
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question