logoalt Hacker News

aizk • today at 3:35 AM • 4 replies • view on HN

It's O(logn) but you haven't accounted for how heavy each item in the array of n is.


Replies

StilesCrisis • today at 12:55 PM

You can just move the lightest half of the boxes each time.

➕ show 1 reply
kelseyfrog • today at 4:34 AM

If you randomly index them and there's enough of them then on average the partitions average out.

mauvehaus • today at 4:06 AM

This is true, but it probably isn't a box of books that's beeping.

I also feel like ordering the moves by lightest box first is reasonable as a real-world optimization.

➕ show 1 reply
tonyarkles • today at 4:04 AM

Lol classic “ignore the constant factor” gotcha when using Big-O.