Hacker News new | past | comments | ask | show | jobs | submit
It's O(logn) but you haven't accounted for how heavy each item in the array of n is.
You can just move the lightest half of the boxes each time.
loading story #50441681
If you randomly index them and there's enough of them then on average the partitions average out.
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.

Typically, the heavy boxes are at the bottom too; to some extent, the piles will already be sorted by weight.
Lol classic “ignore the constant factor” gotcha when using Big-O.