Reported July 2026
Two Sigmasimulation

Closest Color

Reported by candidates from Two Sigma's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Two Sigma OA. Under 2s to a working solution.
Founder's read

Two Sigma reported this one in July 2026, and the input looks harmless until you ask how big the pixel list can get. Each pixel is a 24-bit binary string, and you compare it against exactly five fixed colors. That's a constant-size check per pixel, so there's no clever structure to find. It's a parsing and precision problem dressed up as geometry. The OA wants clean bit slicing, correct distance math, and a tie rule that doesn't bite you. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and hands you the solution while the proctor sees nothing.

The problem

A color is represented as a 24-bit integer, with 8 bits each for red (R), green (G), and blue (B) components. Each component ranges from 0 for low intensity to 255 for high intensity.
The distance between two colors with RGB values (r1, g1, b1) and (r2, g2, b2) is:
d = sqrt((r1 - r2)^2 + (g1 - g2)^2 + (b1 - b2)^2)
Pure colors
Compare each pixel with these five pure colors:
RGB values of the pure colorsPure colorRGB
Black000
White255255255
Red25500
Green02550
Blue00255
Given a list of 24-bit binary strings representing pixel color values, determine which pure color each pixel is closest to.
If a pixel is equally close to multiple colors, use "Ambiguous".

Function
closestColor(pixels: String[]) → String[]

Examples
Example 1
pixels = ["000000001111111100111100"]
return = ["Green"]
Split the binary string into three components of 8 bits each:
R = "00000000", which is 0.
G = "11111111", which is 255.
B = "00111100", which is 60.
Thus, the pixel's RGB value is (0, 255, 60).
The smallest distance is to Green, so the result is "Green".

Constraints
Each value in pixels is a 24-bit binary string.
Each component is represented by 8 bits and ranges from 0 to 255.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that there isn't one. Slice each string into three 8-character chunks, parse each as base 2, then compute the distance to Black, White, Red, Green and Blue. Skip the square root entirely. Comparing squared distances gives the same ordering and keeps everything in integers, so ties are exact. That's the real pitfall: floating point sqrt can make two equal distances look different and break the Ambiguous case. Track the minimum squared distance and a count of how many colors hit it. If the count is above one, output Ambiguous. Another common slip is parsing the whole string as one integer, or slicing the wrong offsets. Work is O(n) with five comparisons per pixel. If the live OA rattles you and the tie logic won't come together, StealthCoder is the hedge that gives you the working version fast.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Closest Color cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Two Sigma's OA.

Two Sigma reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Closest Color FAQ

How hard is Closest Color really?+

Easy. There's no algorithm beyond parsing and a five-way comparison. The difficulty is in the details: slicing the 24-bit string correctly and handling ties without floating point errors. If you code it carefully, it's a ten-minute problem.

What's the trick to avoiding wrong answers on ties?+

Don't use sqrt. Compare squared distances as integers. Two colors are equally close only if their squared distances match exactly, and integers make that check reliable. Then count how many pure colors share the minimum and return Ambiguous if it's more than one.

How do I split the binary string?+

Take characters 0-7 for red, 8-15 for green, and 16-23 for blue. Parse each substring with base 2, like int(s, 2) in Python or parseInt(s, 2) in JavaScript. Check against the example: 00000000 11111111 00111100 gives (0, 255, 60).

Does input size matter for this problem?+

Each pixel costs a constant amount of work, five distance checks, so the total is linear in the number of pixels. Brute force over colors is already optimal. You don't need sorting, hashing, or any data structure beyond the output list.

How do I prepare for this in 48 hours?+

Write it once from scratch. Parse the bits, define the five pure colors as tuples, compute squared distances, handle ties. Then test the example and a few edge cases: pure black, pure white, and a gray pixel like (127, 127, 127) that sits near the middle of the range.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Two Sigma.

OA at Two Sigma?
Invisible during screen share
Get it