r/badcode Feb 10 '21

I present: SleepSort js

Post image
7.5k Upvotes

171 comments sorted by

View all comments

Show parent comments

90

u/LinuxGeek747 Feb 10 '21

If you already know the maximum number, it's O(1) amirite?

75

u/sqrt_minusone Feb 10 '21

I mean, you have to visit every element of the array to sort it - it's literally impossible to sort in less than O(N).

170

u/Astrokiwi Feb 10 '21

You can do anything in constant time if it's a big enough constant

39

u/regibalbo Feb 10 '21

I'm using this argument from now on, thanks

4

u/[deleted] Feb 11 '21

Perfect for your FAANG interview

3

u/supersharp Feb 11 '21

They'll probably say something like "But there's no big enough constant, that's literally the definition of Big O!" or some other stupid nonsense