Tap here to switch tabs
Problem
Submissions

Problem: Similar RGB Color

Try to solve the Similar RGB Color problem.

Statement

An RGB color is represented as a 77 character string "#RRGGBB", consisting of a '#' symbol followed by three color components RR, GG, and BB, where each component consists of two hexadecimal digits.

A shorthand RGB color is a color where each of the three color components consists of two identical hexadecimal characters (such as "#11ee66").

The similarity between two colors color1 and color2 with components (R1,G1,B1)(R_1, G_1, B_1) and (R2,G2,B2)(R_2, G_2, B_2) evaluated in hexadecimal is calculated as:

−(R1−R2)2−(G1−G2)2−(B1−B2)2-(R_1 - R_2)^2 - (G_1 - G_2)^2 - (B_1 - B_2)^2

Given a 77 character string color, return a 77 character string of a shorthand color that maximizes the similarity to color. If there are multiple answers, return any of them.

Constraints:

  • color.length =7= 7

  • color[00] = ext{'\\#'}

  • color[ii] is either a digit or a character in the range ['a', 'f'] for i>0i > 0

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Similar RGB Color

Try to solve the Similar RGB Color problem.

Statement

An RGB color is represented as a 77 character string "#RRGGBB", consisting of a '#' symbol followed by three color components RR, GG, and BB, where each component consists of two hexadecimal digits.

A shorthand RGB color is a color where each of the three color components consists of two identical hexadecimal characters (such as "#11ee66").

The similarity between two colors color1 and color2 with components (R1,G1,B1)(R_1, G_1, B_1) and (R2,G2,B2)(R_2, G_2, B_2) evaluated in hexadecimal is calculated as:

−(R1−R2)2−(G1−G2)2−(B1−B2)2-(R_1 - R_2)^2 - (G_1 - G_2)^2 - (B_1 - B_2)^2

Given a 77 character string color, return a 77 character string of a shorthand color that maximizes the similarity to color. If there are multiple answers, return any of them.

Constraints:

  • color.length =7= 7

  • color[00] = ext{'\\#'}

  • color[ii] is either a digit or a character in the range ['a', 'f'] for i>0i > 0