Feature #3: Find Median Age
Implementing the "Find Median Age" feature for our "Netflix" project.
We'll cover the following...
Description
Our third task is building a filter that will fetch relevant content based on the age of the users for a specific country or region. For this, we use the median age of users and the preferred content for users that fall into that specified category.
Because the number of users is constantly increasing on the Netflix platform, we need to figure out a structure or design that updates the median age of users in real-time. We will have a list that constantly receives age values, and we will output the median value after each new data point.
Let’s understand this better with an illustration:
Solution
We will assume that ‘x’ is the median age of a user in a list. Half of the ages in the list will be smaller than (or equal to) ‘x’, and the other half will be greater than (or equal to) ‘x’. We can divide the list into two halves: one half to store the smaller numbers (say smallList
), and one half to store the larger numbers (say largeList
). The median of all ages will either be the largest number in the smallList
or the smallest number in ...