I'm trying to create an initial solution to the group balancing problem, but I seem to be stuck with what sounds like it should be pretty simple.
Basically I have an array of weights (random integers) like
W() = [1, 4, 3, 2, 5, 3, 2, 1]
And I want to create another array of the same length with numbers 1 to the size of the array instead of the smallest and largest numbers respectively, for example.
S() = [1, 7, 5, 3, 8, 6, 4, 2]
For duplicates, the first occurrence is taken as the smaller of the indices.
I originally used the BubbleSort algorithm, but, unfortunately, this does not allow me to output in the required format.
I understand that this is a rather specific problem, but any help would be greatly appreciated.