Skip to main content
1 of 2
Kenneth Kho
  • 765
  • 3
  • 17

Here's how to do it for $false$ stable:

Let $i = 0$, go through every element from left to right, and each time we see a $false$ element, swap it to index $i$, and increment $i$. The time complexity is $O(n)$ and the auxiliary space is $O(1)$.

It is similar for $true$ stable, but impossible for both stable.

Kenneth Kho
  • 765
  • 3
  • 17