Wish I Knew How to Sort
HardRating 2000CodeforcesMixed Practice
Approach hintTry it first, then revealHide
Let z be the number of zeros and k the number of ones among the first z positions. Only a swap of a misplaced one with a misplaced zero helps, with probability k^2 / C(n, 2); sum the expected waits as k falls to zero.