I am trying to solve a Data Structures and Algorithms problem, which states that given a group of 1s and 0s, group the digits such that all 0s are together and all 1s are together. What is the minimum number of swaps required to accomplish this if one can only swap two adjacent elements? It does not matter which group is at what end.
Eg:
[0,1,0,1] = [0,0,1,1] 1 swaps
[1,1,1,1,0,1,0] = [1,1,1,1,1,0,0] 1 swaps
[1, 0, 1, 0, 0, 0, 0, 1] = = [1,1,1,0,0,0,0,0] 6 swaps
Note that this is different from the questions asked here:
Find the minimum number of swaps required such that all the 0s and all the 1s are together
I am not sorting the array, I am just trying to group all the 0s and all the 1s together and it does not matter which is at which end.
I really have no clue where to even start. Can someone help me?