Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Twin Outliers

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Split two unique values by one differing bit: The Twin Outliers.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Single Number III matches the clues
  2. 2Keep this true after every move: each duplicate enters one bucket twice and cancels, while the uniques enter opposite buckets
  3. 3Reach the result within O(n) time and O(1) space

Rules and pressure

  • Target cost: O(n) time and O(1) space
  • State rule: each duplicate enters one bucket twice and cancels, while the uniques enter opposite buckets
Lesson 1 of 3

Live algorithm trace

Single Number III

Complete execution
1 of 5

XOR the full array so all paired values cancel.

1combined = XOR of all values
2mask = combined & -combined
3left = right = 0
4partition values by mask bit
5XOR within each bucket
6return the two bucket results
combined = 3 XOR 5 = 6binary = 110
Truth to preserve / Cost target
Truth to preserve

each duplicate enters one bucket twice and cancels, while the uniques enter opposite buckets

Cost target

O(n) time and O(1) space

XOR cancels every pair, leaving uniqueA XOR uniqueB. Any set bit in that result separates the two uniques into different XOR buckets.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead