Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Tries

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Tries

Maximum XOR of Two Numbers in an Array

advancedlayer A5 · Tries5 tests

Given an array nums, return the largest value of nums[i] ^ nums[j] over all pairs of indices (i and j may be equal).

  • Every value satisfies 0 <= nums[i] < 2**31, so results always stay non-negative
  • The array can hold hundreds of thousands of values, so the O(n^2) double loop is out — aim for O(n · 31)
  • A one-element array answers 0, since XOR-ing a value with itself gives 0

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen