Contiguous Run of Packet Checksums With Maximum XOR
Last updated: November 29, 2026
Quick Overview
Given an array of non-negative integers, find the maximum XOR of any non-empty contiguous subarray in O(n x bits) time.
0
0
0 solved
Given an array of non-negative integers, find the maximum XOR of any non-empty contiguous subarray in O(n x bits) time.
A Google technical screen problem that combines prefix XORs with a binary trie, framed around checksum blocks in a network capture. The interviewer checks that you convert the subarray XOR into the XOR of two prefix values and reuse the max-XOR-pair trie.
What the Interviewer Expects
- Define prefix XOR p[i] and show subarray XOR equals p[j] ^ p[i]
- Insert prefix 0 before processing so subarrays starting at index 0 count
- Query the trie for the best partner before inserting the current prefix
- Explain why the greedy opposite-bit walk is optimal
- Return the subarray bounds as a follow-up
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the start and end indices of the best run?
- How would you find the maximum XOR subarray of length at most k?
- How would you count subarrays whose XOR equals a target?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: nums, a non-empty list of integers below 2^31. Output: the maximum value of nums[i] ^ nums[i+1] ^ ... ^ nums[j] over all i <= j....
High-Level Design
Let p[0] = 0 and p[k] = nums[0] ^ ... ^ nums[k-1]. Because XOR cancels itself, the XOR of nums[i..j] equals p[j+1] ^ p[i]. So the problem becomes: maximize p[b] ^ p[a] over a < b. Scanning...