views:

167

answers:

2

Let's say you are helping setting up the Olympics on an alien planet. You are in charge of making the Olympic flag. The Olympic flag would have 6 colors. The flags of every country on the planet must have one of the six colors on the Olympic flag. You already know the colors on a flag. How would you compute the colors on the Olympic flag? The flag colors are contained in an array of arrays.

A: 

Assuming the number of colors is reasonably limited (e.g., if there are 12 colors, there are 924 combinations of 6 of them), I'd use brute force.

dan04
A: 

My solution: I would create a hash table where key=color, value = integer. Next, I would iterate the countries' flags. for each color I would apply hash(color)++. The colors on the olympic flag are the top 6 colors after sorting the hash table by its values (Where values are are sorted from largest to lowest)

Protostome
Doesn't take account of groupings of colours: e.g. the extreme case where 51% of the countries' flags use the same six colours, which are used by none of the other countries.
DJClayworth