Press "Enter" to skip to content

How to find the most popular person in a group of people

Ajk 0

Today, I wanted to take a stab at a social media type question that I was asked once upon a time. How to find the most popular person in a group of people.
In our set up, we assume we are given a 2D array of people who follow one another. (i.e. fi A[i][j] is true, it means that person i follows person j)

I only have 10 minutes, so I’ll try to cut it as short as possible and make a quick overview on a small social media functionality.

Bbelow is the code. I cannot think of an optimization we can do at the moment.
Worst time-complexity seems O(n2) and no way to go around it.
Auxiliary space-complexity is also O(n) in the worst case scenario. Below the code:

How to find the most popular person in a group of people.

I do not think there is an easier way, since in the worst case scenario you HAVE TO go through each node (total nodes, n squared), to find out if a person follows / gets followed.
Great now you know a a little piece of implementation of social media following / most popular person abstraction.

Hope you guys enjoyed it… and I’ll see you guys next timd ;D

The following two tabs change content below.
If you like one of my posts the best way to support is give it a thumbs up, comment, or share it on social media 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *