Atlassian SDE 2
Summary
I was presented with a challenging problem to design a class for tracking content popularity from a continuous stream of actions and retrieving the most popular content ID efficiently.
Full Experience
During my interview round, I was given a data structures and algorithms problem. The interviewer asked me to implement a class that could manage content popularity based on a stream of incoming actions. The key was to efficiently handle both increasing and decreasing popularity for specific content IDs, and then, at any point, be able to return the ID of the most popular content. This required careful consideration of data structures to ensure real-time performance for all operations.
Interview Questions (1)
Most Popular Content ID from Stream
Imagine you are given a stream of content IDs along with an associated action to be performed on them.
Examples of contents are video, pages, posts etc.
There can be two actions associated with a content ID:
- increasePopularity: increases the popularity of the content by 1. The popularity increases when someone comments on the content or likes the content.
- decreasePopularity: decreases the popularity of the content by 1. The popularity decreases when a spam bot’s/user's comments are deleted from the content or its likes are removed from the content.
Implement a class that can return the mostPopular content ID at any time while consuming the stream of content IDs and its associated action. If there are no content IDs with popularity greater than 0, return -1.