Just want to rearrange the data in array so that similar items are not next to each. The data should not be removed from the array, if it can't be rearranged it can be put at the end of the array. But keeping the original order is necessary.
Example
1 1 2 => 1 2 1
1 1 1 2 3 => 1 2 1 3 1
1 1 2 1 3 3 5 1 => 1 2 1 3 1 3 5 1
1 1 1 1 1 1 2 => 1 2 1 1 1 1 1
8 2 1 3 7 2 5 => rearrange not needed
8 2 2 2 7 2 5 2 => 8 2 7 2 5 2 2 // keep the original order
EDIT: Added example to show keeping original order is needed