3 ms·
> 2) Given an array of zeroes and ones, sort it stably using O(n) time and O(1) extra space. I'm missing something here. If the array's values truly are all i
by pklausler 10y ago
> 2) Given an array of zeroes and ones, sort it stably using O(n) time and O(1) extra space.
I'm missing something here. If the array's values truly are all in {0,1}, then all the zeroes are indistinguishable and you get stability for free (same for the ones).
mysort all01list = let ones = sum all01list in replicate (length all01list - ones) 0 ++ replicate ones 1
- cousin_it 10y agoSee openasocket's question and mkingston's answer in another subthread.