Feature #6: Fetch Most Frequently Watched Titles
We'll cover the following...
Description
This feature and the one we discussed before are almost similar, but now the titles are maintained in order of viewing/access frequency. When the data structure is at capacity, a newly inserted item will replace the least frequently accessed item. In the case of a tie, the least recently accessed item should be replaced.
Let’s say that a user has gone through the following titles:
We need to design a structure that takes the ID of the movies and adds them to our structure. It also needs to fetch a movie title when accessed through its ID. We also have to consider the size of the data structure and maintain the least frequently watched property.
Here is an illustration of this process:
Solution
We’ll build this structure on top of the one from the previous lesson. We will also use a Hash Map and a doubly linked list. In this case, we’ll also store data on how frequently titles are accessed along with their respective keys and values. We’ll append each new entry at the tail of the doubly linked list. A Hash Map will be used to keep track of the keys and their values in the linked list.
You could create a Hash Map that will store the key, value, and frequency count for that value. Since multiple titles can have the same access frequency, the value stored in the Hash Map for each key will be a doubly linked list. The ...
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy