The vote tracking part I got pretty quickly, just a map from user to current vote state.
Start by clarifying requirements and scale, then propose a data model that stores per-article vote counts and a bounded history of recent vote flips. Use a hash map for O(1) access to article state and a fixed-size circular buffer or deque for the last three flips, ensuring constant-time updates and queries.
Pro tip: Emphasize that the O(1) query requirement applies to retrieving the article's state and recent flips, not to updating votes; this distinction shows you understand the problem's constraints. Also, mention that the history can be stored per article without affecting scalability if you shard by article ID.
Ask about expected scale (number of articles, votes per second), consistency needs, and whether the last three flips must be strictly ordered by time. Confirm that O(1) is required for queries, not updates.
Propose a per-article record containing thumbs-up count, thumbs-down count, and a fixed-size history buffer (e.g., circular array of size 3) for recent flips. Use a hash map keyed by article ID for O(1) access.
When a user changes their vote, update the counts and append the flip action to the history buffer, evicting the oldest if full. Ensure the buffer maintains chronological order.
For a query, retrieve the article record from the hash map, return the counts and the contents of the history buffer in order. Since the buffer size is constant, this is O(1).
Discuss sharding by article ID, handling concurrent votes, and persistence. Mention edge cases like no votes yet or fewer than three flips.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.