Magicsheet logo

Find Followers Count

Easy
95.3%
Updated 6/1/2025

Find Followers Count

What is this problem about?

The Find Followers Count coding problem is a SQL task that involves analyzing social media data. You are given a Followers table with two columns: user_id and follower_id. Each row represents a relationship where the follower_id follows the user_id. Your task is to calculate the total number of followers for each user and return the results sorted by user_id.

Why is this asked in interviews?

Tech giants like Tesla and Meta use this Find Followers Count interview question to test a candidate's understanding of basic relational database operations. It evaluates your ability to use the GROUP BY clause and the COUNT() aggregate function. It also tests whether you can produce a well-formatted and ordered report, which is a daily task for backend and data engineers.

Algorithmic pattern used

This is a standard Database Aggregation problem. The logic is:

  1. Target the Followers table.
  2. Group the rows based on the user_id.
  3. For each group, count the unique follower_id entries (though usually, the table doesn't have duplicates, COUNT(*) or COUNT(follower_id) is sufficient).
  4. Order the final result set by user_id.

Example explanation

Table Followers:

user_idfollower_id
12
13
21
  1. Group by user_id 1: There are two rows (followers 2 and 3). Count = 2.
  2. Group by user_id 2: There is one row (follower 1). Count = 1.
  3. Result:
    • 1: 2
    • 2: 1

Common mistakes candidates make

  • Incorrect Grouping: Grouping by follower_id instead of user_id, which would count how many people a user follows, not how many follow them.
  • Missing Order: Forgetting the ORDER BY user_id clause, which is often required for the output to be accepted.
  • Null Handling: Not accounting for users who have no followers (though they usually wouldn't appear in this specific table depending on the schema).

Interview preparation tip

Master the differences between COUNT(*), COUNT(column), and COUNT(DISTINCT column). In this problem, COUNT(follower_id) is typically used to represent the specific relationship being counted.

Similar Questions