Dropping spaghetti is an O(1) operation. Once that's done there's a straightforward O(N) sort by removing noodles in the order that they're intersected by horizontal plane descending from max_noodle_length to the table.