Snap
Closed this issue · 1 comments
darrenfu commented
12/06/2019
-
Given a pool of airplanes, some are randomly landing, design a taking off sequence strategy.
Ground rules:
- Passenger planes are always ahead of Cargo planes.
- Larger size planes are always ahead of light planes.
- Planes with longer waiting time on the ground are always ahead of planes with shorter times.
darrenfu commented
intuition for the 2nd question:
- Heapify all landed planes into two max-heap by plane's size: passenger heap and cargo heap. If some plane lands, push to one of the heap.
- If two planes are with the same size, store a sub-max-heap as the heap element instead to always have the plane with longest waiting time on the heap top.
- When we need some plane to take off, always choose passenger heap first; then pop the heap top element, and if there are sub-heap on this element, pop the sub-heap element, which is the plane with longest waiting time.