Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Maximum XOR of Two Numbers in an Array

Medium

Topics
ArrayBit ManipulationTrieHash Table

Given an integer array nums, return the maximum result of nums[i] XOR nums[j] over all pairs 0 <= i <= j < n.

Example 1

Input:  nums = [3,10,5,25,2,8]
Output: 28
Explanation: 5 XOR 25 = 28 is the largest pairwise XOR.

Example 2

Input:  nums = [14,70,53,83,49,91,36,80,92,51,66,70]
Output: 127

Example 3

Input:  nums = [0]
Output: 0

Constraints

  • 1 <= nums.length <= 2 * 10^5
  • 0 <= nums[i] < 2^31
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access