title: What is the minimum number of adjacent swaps needed to segregate a list of 0s and 1s?
body: <p>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.</p>
  <p>Eg:</p>
  <p>[0,1,0,1] = [0,0,1,1] 1 swaps</p>
  <p>[1,1,1,1,0,1,0] = [1,1,1,1,1,0,0] 1 swaps</p>
  <p>[1, 0, 1, 0, 0, 0, 0, 1] = = [1,1,1,0,0,0,0,0] 6 swaps</p>
  <p>Note that this is different from the questions asked here:</p>
  <p><a href="https://stackoverflow.com/questions/57265324/find-the-minimum-number-of-swaps-required-such-that-all-the-0s-and-all-the-1s-ar">Find the minimum number of swaps required such that all the 0s and all the 1s are together</a></p>
  <p>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.</p>
  <p>I really have no clue where to even start. Can someone help me?</p>