Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hey Haroen,
- thank you for the interview again, it's been a real pleasure.
- One thing I would like to add is there is a very simple optimization to the "package in a box" problem that I just thought of. It's still not a complete solution, but it should yield pretty good solution for uniformly distributed data:
- you could instead of collecting into a Vec<Package>, use a sorted VecDeque<Package>, and then alternate between popping elements from back and front. This should result in a much smaller amount of reduntant Boxes.
- even better solution:
- each insert into the box should iterate over sorted Vec<Package>, this time biggest to smallest and pick the biggest one that can fit. In order to not iterate over all elements each time, you could store the index of the last "popped/removed" entry and only go down starting from that index (as the remaining Box capacity will only go down, so there is no point in checking Packages that's already been checked).
- Then, another optimization would be to not use Vec<Package>, but rather a LinkedList, so that the "remove" operation doesn't reallocate the entire container.
- I swear I didn't google this, I'm just not very good at thinking fast under pressure, it just occurred to me when I was making tea :D.
- cheers,
- Wojciech
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement