I went straight for two hashmaps, one to track current vote state per user/article pair and one to store the event log per user.
Clarify requirements and edge cases, then design a data structure that stores the current vote state per user-article pair and a per-user history of vote events. Implement vote() to update state and append to history only when the vote changes, and getLastVotes() to return the last 3 events in reverse chronological order.
Pro tip: Discuss trade-offs between memory and performance, and mention that in a real system you'd consider persistence, concurrency, and scalability—showing you think beyond the basic implementation.
Ask questions to confirm: what defines a vote event? Should duplicate votes be ignored? What about flipping votes? How many recent votes to return? Are there multiple articles per user?
Choose structures to track current vote state (e.g., a map from (user, article) to vote type) and per-user vote history (e.g., a map from user to a deque or list of events).
On vote, check current state: if same as new vote, do nothing; if different or no previous vote, update state and append a new event to the user's history.
Retrieve the user's history and return the last 3 events in reverse chronological order, handling cases with fewer than 3 events.
State time and space complexity, and mention potential improvements like persistence, concurrency, or scalability for production.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.