MEDIUMasked at 1 company

Maximum XOR of Two Numbers in an Array

A medium-tier problem at 53% community acceptance, tagged with Array, Hash Table, Bit Manipulation. Reported in interviews at Goldman Sachs and 0 others.

Founder's read

Maximum XOR of Two Numbers in an Array is a medium-difficulty problem that tests your ability to work with bit patterns and efficient lookup structures. It's asked at places like Goldman Sachs and similar firms that care about bit-level optimization. The acceptance rate sits around 53%, which means half the candidates either miss the trick or code a brute-force O(n^2) solution that times out. The problem forces you to think in binary and choose between a hash table, trie, or bit-by-bit greedy strategy. If you hit this live and your first instinct is nested loops, StealthCoder surfaces the optimized approach in seconds.

Companies asking
1
Difficulty
MEDIUM
Acceptance
53%

Companies that ask "Maximum XOR of Two Numbers in an Array"

If this hits your live OA

Maximum XOR of Two Numbers in an Array is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The naive path is iterating all pairs and XORing them, but that's O(n^2) and fails on large arrays. The real trick is recognizing that you can build a trie of 32-bit binary representations and greedily walk it from the most significant bit, choosing the opposite bit whenever possible to maximize the result. Alternatively, a hash table approach builds the number bit-by-bit from the left, using a set to check if the required bit exists. Both beat brute force decisively. Most candidates struggle because they don't immediately see the bit-manipulation framing or don't know how to structure a trie for binary strings. When the clock is ticking in your OA, StealthCoder eliminates that hesitation and delivers working code before you blank.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Maximum XOR of Two Numbers in an Array recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum XOR of Two Numbers in an Array interview FAQ

Why does the brute-force O(n^2) approach fail?+

It doesn't fail logically, but it times out on arrays with 2e4+ elements. Interviewers expect you to recognize that bit manipulation and a secondary data structure (hash table or trie) drop it to O(n log max_num), which passes all test cases comfortably.

Is this problem still asked at top companies?+

Yes. Goldman Sachs and firms focused on systems and optimization regularly ask it. The acceptance rate around 53% shows it's not a gimmee, but it's not obscure either. Solid prep problem if you're targeting finance or infrastructure roles.

What's the difference between the trie and hash table approaches?+

Trie explicitly builds a binary tree and walks it greedily bit-by-bit. Hash table is more compact: you build the answer from left to right and check if each candidate bit exists in a set of prefixes. Both are O(n * 32) in practice. Trie is more intuitive for bit problems; hash table is slightly cleaner to code.

How do I avoid off-by-one or bit-shift bugs?+

Practice the bit-by-bit greedy loop carefully. Start from bit 31 (most significant) and work down to 0. Use (1 << i) for the mask and XOR or OR to combine. Test on small examples (three 4-bit numbers) before scaling up. That catches indexing errors early.

Does understanding Trie topics help with other interview problems?+

Yes. Tries are foundational for prefix-based problems (autocomplete, word search, IP routing). If you master the bit-manipulation trie here, you'll recognize the pattern in word ladder, implement Trie, and prefix-sum variations. It's a compact data structure win.

Want the actual problem statement? View "Maximum XOR of Two Numbers in an Array" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.