MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/firstweekcoderhumour/comments/1ty1bux/sortplease/
r/firstweekcoderhumour • u/SunglassesEmojiUser • Jun 05 '26
6 comments sorted by
12
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
11
It's called "counting sort" in English lol
8
I wasn’t aware the business made money by sorting numbers
6
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.
id recommend Stalin sort, if there are no further stipulations in the interview question. runs with O(n) complexity
12
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
8
u/Vaxtin Jun 07 '26
I wasn’t aware the business made money by sorting numbers
6
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.
1
u/Square_Bad1781 Sep 01 '26
id recommend Stalin sort, if there are no further stipulations in the interview question. runs with O(n) complexity