you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 1 year ago*

This algorithm takes K seconds where K is the value of the greatest element.

This means if you just multiply everything by -1 it will take negative time to sort.

Then you can simply unmultiply and read from end to beginning from now on.

This is faster than having it presorted.

  • source