# The container you pick is a claim about order

A lift's pending stops arrive one call at a time, so the container that comes to mind is a queue.
`std::queue<int>` is spelled `ArrayDeque<Integer>` here, and the code writes itself:

```java
Deque<Integer> stops = new ArrayDeque<>();
```

Lift 1 stands on floor 4 travelling UP. Calls arrive for 9, then 2, then 7. Taking them off the
head, it serves `[9, 2, 7]` in 20 ticks and sails past floor 7 twice without opening its doors.
`ElevatorApi` says stops are served in **direction order, not arrival order**. Arrival order is the
one thing a queue is built to remember, and the one thing a lift has to throw away.

What the lift asks is "which pending floor is nearest at or above me". That is a question about
order, so the container has to keep order:

```java
NavigableMap<Integer, Integer> stops = new TreeMap<>();  // floor -> riders bound for it
stops.ceilingKey(4);                                     // 7
```

Now it serves `[7, 9, 2]` in 15 ticks. `std::map` did this for you, and its Java spelling is
`TreeMap` — `HashMap` is `unordered_map`.

Then `pendingStops()` has to hand the floors back ascending, and a `HashSet<Integer>` looks like it
already does. In the ten-floor building it does: adding 9, 2, 7, 4 iterates `[2, 4, 7, 9]`, because
`Integer.hashCode()` is the value itself. Move to a twenty-floor tower and adding 19, 3, 12, 5
iterates `[19, 3, 5, 12]`.

Nothing threw. Every test you wrote against ten floors still passes.
