This question evaluates a candidate's ability to design efficient in-memory data structures, reason about API semantics and edge-case behavior, analyze time and space complexity, and consider concurrency control for a key-value store with a getLast operation.
Design and implement an in-memory key–value store with this API: add(key, value), get(key), remove(key), and getLast(). The operation getLast() must return the most recently added entry that still exists in the store. Calling get(key) must not change which element is considered "last." Specify behavior for edge cases: adding an existing key (overwrite vs. reject), removing the current last element (the next most recent becomes last), and calling getLast() on an empty store (return sentinel or throw). Target O(