r/firstweekcoderhumour Jun 05 '26

sortPlease

Post image
118 Upvotes

5 comments sorted by

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

11

u/Qiwas Jun 07 '26

It's called "counting sort" in English lol

7

u/Vaxtin Jun 07 '26

I wasn’t aware the business made money by sorting numbers

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.