I have a list of email address which I want to distribute evenly by domain.
For example:
let the list be,
a@a.com b@a.com c@a.com a@b.com b@b.com c@c.com
The output should be
a@a.com a@b.com c@c.com b@a.com b@b.com c@a.com
The source list is not sorted by domain as in example, but can be sorted by domain, if that can help. What would be an efficient (single/two pass?) algorithm of doing this?
raj
Here is my solution to this problem. Given an input like
The output is
Ruby source of the program is:
The idea is to take the alphabet with highest frequency and distribute it first across an array whose size is the total number of all elements. Next distribute the alphabet with second highest frequency and distribute it across the free spaces and so on.
If you have questions let me know and I am happy to answer.
raj