Problem · Design
Article Vote Tracker
Learn this problemProblem statement
Build an in-memory vote-management service for an online news platform. Users may upvote or downvote published articles, and the service tracks the articles on which each user most recently changed their vote.
Process the operations in order and return one row for each operation that produces output.
Operations
["ADD", articleName]: add an article. Article IDs start at1and increase by one. Return the assigned ID as a one-element row.["UPVOTE", articleId, userId]: record an upvote. The article ID is valid, and any user ID is allowed.["DOWNVOTE", articleId, userId]: record a downvote. The article ID is valid, and any user ID is allowed.["LAST_THREE", userId]: return the titles of the last three distinct articles on which the user flipped their vote from upvote to downvote or from downvote to upvote. Return the most recent title first.
Casting the same vote repeatedly is not a flip. If a user flips the same article again, that article becomes the most recent entry and appears only once in the result.
Do not use persistent storage, and do not consider thread safety.
Function
processArticleVotes(operations: String[][]) → String[][]Examples
Example 1
operations = [["ADD","Alpha"],["ADD","Beta"],["ADD","Gamma"],["UPVOTE","1","u1"],["UPVOTE","2","u1"],["DOWNVOTE","1","u1"],["DOWNVOTE","2","u1"],["UPVOTE","1","u1"],["UPVOTE","3","u1"],["LAST_THREE","u1"]]return = [["1"],["2"],["3"],["Alpha","Beta"]]The first three rows are the assigned article IDs. Alpha and Beta both receive vote flips. Alpha is flipped again later, so it moves ahead of Beta. Gamma's first vote is not a flip.
More Rippling problems
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Camel CardsPHONE SCREEN · Seen May 2026
- Employee Resource Access ManagementONSITE INTERVIEW · Seen Jan 2026
- Limit an Organization Tree's HeightONSITE INTERVIEW · Seen Aug 2025
- Distributed System RecoveryOA · Seen Jul 2025
- Server Upgrade PlanningOA · Seen Jul 2025
- Shortest SubstringOA · Seen Jul 2025