I came across the following problem in the book "Elements of Programming Interviews in Python".
Given an array A of n objects with Boolean-valued keys, reorder the array so that objects that have the key false appear first. The relative ordering of objects with key $true$ should not change. Use $O(1)$ additional space and $O(n)$ times.
My question is, is there an algorithm with $O(1)$ additional space and $O(n)$ time to keep the relative ordering for element with $true$ AND $false$ keys? If so, what is the algorithm? If not, how can I prove it is not possible?
The algorithms I could think about were either $O(n^2)$ or used $O(n)$ additional space.