Hacker News new | ask | show | jobs
by AndrewDucker 22 days ago
Assuming that the spaghetti is being held in such a way that longer pieces hit the surface first. If the pieces are being held at random points, or such that the bottoms line up rather than the tops, then this approach won't work.
1 comments

You don't have to assume that. We can take each randomly oriented noodle and orient it correctly in O(1) as a preprocessing step. Since the complexity would be additive, the overall complexity remains O(N).