I need an algorithm that distributes same items across a list, so maximizing the distance between occurrences.
E.g. I have a list of 15 items:
{a,b,c,c,c,d,e,f,f,f,g,h,h,i,j}
The algorithm should reorder these in such a way that all the duplicates are spread as uniformly as possible.
The mentioned list should result in something like this:
{c,f,a,h,b,c,d,e,c,f,g,c,h,i,j,f}
Preferably I'd like pseudo code, and even better would be TSQL (since that is the platform it needs to run on). It needs to process hundreds of these lists in one go.
I also tested a proposed method called 'Weighted shuffle' but this will still allow two of the same items in the list to appear next to each other even when this is not needed.