Hacker News new | ask | show | jobs
by aizk 24 days ago
It's O(logn) but you haven't accounted for how heavy each item in the array of n is.
4 comments

If you randomly index them and there's enough of them then on average the partitions average out.
You can just move the lightest half of the boxes each time.
A few additional constraints:

  - the boxes are stacked
  - the heavy boxes are at the bottom of a stack, and you can't stack a heavy box on top of a light one
  - boxes aren't the same size
  - some boxes are open, so must be put on top
  - storage space and height are limited
Some boxes contain a wolf, some a sheep, and some a cabbage; the sheep and the wolf cannot be left together, nor the cabbage and the sheep.
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.
This is a pretty good real world example to show off how O(n) can't always tell the full story.