In the RGB color model, colors are encoded as triples (R, G, B), where R, G and B denote the quantity of red, green and blue, respectively, in the color. Each number in the triple is between 0 and 255, inclusive. The distance between two colors (R1, G1, B1) and (R2, G2, B2) is max{|R1-R2|, |G1-G2|, |B1-B2|}. The distance between a color C and a set of colors S is the maximum among the distances between C and each color in S. A best approximation for a set of colors S is a color C such that the distance between C and S is as small as possible.
You will be given a String[] colors, each element of which contains a single space separated list of colors, with no leading or trailing spaces. Each color in the list will be formatted as "RRGGBB" (quotes for clarity), where RR, GG and BB are the color's two-digit red, green and blue quantities, respectively, in hexadecimal notation. All letters will be uppercase. Find the best approximation for this set of colors and return it as a String in the same format as the input colors. If there are multiple possible answers, return the String among them that comes first alphabetically. |