get, add, remove, and getLast.get(key) must leave the result of getLast() unchanged.Use the following language-neutral interface:
get(key) -> value | null
add(key, value) -> void
remove(key) -> void
getLast() -> key | null
For the examples below, interpret getLast() as returning the most recently inserted key that is still present. Confirm this interpretation with the interviewer, since the desired meaning may differ.
add("red", 14)
add("blue", 27)
get("red") -> 14
getLast() -> "blue"
The lookup returns the value for "red" but does not alter insertion order, so "blue" remains the last key.
add("oak", 5)
add("pine", 9)
remove("pine")
getLast() -> "oak"
After "pine" is removed, "oak" is the newest key left in the store.
add("cat", 3)
add("dog", 8)
get("dog") -> 8
getLast() -> "dog"
Reading "dog" does not promote it or otherwise change the last-key result.
get and getLast return null for missing results.