FastPrepClosest Color
Problems/Closest Color

Closest Color

Two Sigma logoTwo Sigma● EasyOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The screenshots show the rules, function name, and worked example, but the bottom of the Function Description is cut off. FastPrep kept the coding contract strictly to the visible details: a list of 24-bit binary strings in, color names out. If we come across a fuller version later, we will update this.

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 colors
Pure 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.

More Two Sigma Online Assessment questions

  • IPO Share AllocationOA · Seen Sep 2026
  • Sewer Drainage PartitionOA · Seen Sep 2026
  • Daily Temperature By TownOA · Seen Sep 2026
  • Linear InterpolatorOA · Seen Sep 2026
  • Online No-Intercept Linear RegressionOA · Seen Sep 2026
  • Balanced Split String with WildcardsOA · Seen Aug 2026
  • Piecewise Linear Interpolation and ExtrapolationOA · Seen May 2026
  • Calculate y/x using PatchOA · Seen Nov 2025
  • Nums That Are Divisible by N 🍋OA · Seen Mar 2024
  • Replacing Val 🍓OA · Seen Mar 2024

Similar questions at other companies

  • Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
  • Price Deviation AlertsJane Street · OAJane Street interview questions
  • Maximum Equal Parts for PrefixesAmazon · OA
  • Most Cost-Effective MachineCapital One · ONSITE INTERVIEWCapital One interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Eight-Direction Keyboard Typing TimeBenchling · PHONE SCREENBenchling interview questions
  • Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
  • REST API: Country CodesHackerRank · OAHackerRank interview questions
  • Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
All Two Sigma interview questionsSee Two Sigma hiring insights
Saved
class Solution {
    public String[] closestColor(String[] pixels) {
      // write your code here
    }

}
Checking account…