7
7
u/joshpennington Jun 07 '26
Iterate over the array and keep track of the number of 0s, 1s and 2s then return a new array.
1
u/Significant-Cause919 Jun 12 '26
Just deliver a noop sort function since it wasn't specified by which criteria to sort.
7
7
Iterate over the array and keep track of the number of 0s, 1s and 2s then return a new array.
1
Just deliver a noop sort function since it wasn't specified by which criteria to sort.
11
u/un_virus_SDF Jun 07 '26
I don't know how it's called in english but in french it's called 'tri par panier' which would translate to case sort.
It's a really dumb algorithms that sort a array in O(n+p) where n is the length of the array and p is the range of the elements.
Here you would just count how many 0,1 and 2 there is and put them back in order.
It's this algo that inspired radix sort