Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Let me check if I got the idea.
Let's say we have [1, 2, 1, 0]
In the first pass, we count the number of occurrences for zeroes, ones and twos:
0:0, 1:2, 2:1
And in the second run, we restore the array. Did I get the idea?
If I understood you correctly, then the described algorithm does not work in-place, right?
EDIT: I noted that my post doesn't emphasize that the provided solution works in-place. Thanks for the remark, updated the article.
Algorithms in Go: Dutch National Flag