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.
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.
This is a standard Database Aggregation problem. The logic is:
Followers table.user_id.follower_id entries (though usually, the table doesn't have duplicates, COUNT(*) or COUNT(follower_id) is sufficient).user_id.Table Followers:
| user_id | follower_id |
|---|---|
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
follower_id instead of user_id, which would count how many people a user follows, not how many follow them.ORDER BY user_id clause, which is often required for the output to be accepted.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.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Fix Names in a Table | Easy | Solve | |
| Not Boring Movies | Easy | Solve | |
| Primary Department for Each Employee | Easy | Solve | |
| Queries Quality and Percentage | Easy | Solve | |
| Combine Two Tables | Easy | Solve |