SoFi·Software Engineer·Technical Phone Screen
- Design and implement an in-memory key-value store with add(key, value), get(key), remove(key), and getLast() operations, where getLast() returns the most recently added entry that still exists. get() should not affect what counts as 'last'. All operations should run in O(1) average time. Cover edge cases, justify your data structure choices, provide pseudocode, and analyze complexity.
- How would you handle concurrent adds and removes in this key-value store, and what locking strategy would you use?
“I went straight to a hashmap for the key-value part and a stack or queue for tracking order, which was wrong because remove() in the middle breaks everything.”