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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
prefix XOR
binary trie
subarray
greedy
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported