Implement an article voting tracker
RipplingSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's ability to design efficient stateful data structures and algorithms for tracking user votes, including correct handling of idempotent repeated votes, vote changes, deduplication, and retrieval of the most recent events.
Coding: Article Voting Tracker
Design and implement a data structure to track users’ votes (upvote/downvote) on articles.
Operations
Implement functions/methods with the following behavior:
vote(userId, articleId, voteType)wherevoteType ∈ {UP, DOWN}
- Track the user’s vote on the article.
- If the user repeats the same vote on the same article (e.g., UP then UP again), it should be counted only once (i.e., do not record a new vote event).
- If the user changes their vote on the same article (e.g., UP then DOWN, or DOWN then UP), it should be counted as a new vote event.
getLastVotes(userId)
- Return (or print) the user’s last 3 vote events, most recent first.
- Each returned event should include at least:
(articleId, voteType, timestamp-or-order).
Notes / constraints
- Assume many users and articles.
- The focus is on correct behavior and efficient operations.
- Define and handle edge cases (e.g., user has < 3 vote events; unknown user).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.