{ "data": { "question": { "questionId": "1877", "questionFrontendId": "1729", "boundTopicId": null, "title": "Find Followers Count", "titleSlug": "find-followers-count", "content": "
Table: Followers
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| user_id | int |\n| follower_id | int |\n+-------------+------+\n(user_id, follower_id) is the primary key (combination of columns with unique values) for this table.\nThis table contains the IDs of a user and a follower in a social media app where the follower follows the user.\n\n
\n\n
Write a solution that will, for each user, return the number of followers.
\n\nReturn the result table ordered by user_id
in ascending order.
The result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nFollowers table:\n+---------+-------------+\n| user_id | follower_id |\n+---------+-------------+\n| 0 | 1 |\n| 1 | 0 |\n| 2 | 0 |\n| 2 | 1 |\n+---------+-------------+\nOutput: \n+---------+----------------+\n| user_id | followers_count|\n+---------+----------------+\n| 0 | 1 |\n| 1 | 1 |\n| 2 | 2 |\n+---------+----------------+\nExplanation: \nThe followers of 0 are {1}\nThe followers of 1 are {0}\nThe followers of 2 are {0,1}\n\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Easy", "likes": 483, "dislikes": 29, "isLiked": null, "similarQuestions": "[]", "exampleTestcases": "{\"headers\":{\"Followers\":[\"user_id\",\"follower_id\"]},\"rows\":{\"Followers\":[[\"0\",\"1\"],[\"1\",\"0\"],[\"2\",\"0\"],[\"2\",\"1\"]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below\n", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Pandas", "langSlug": "pythondata", "code": "import pandas as pd\n\ndef count_followers(followers: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"119.8K\", \"totalSubmission\": \"173.9K\", \"totalAcceptedRaw\": 119793, \"totalSubmissionRaw\": 173880, \"acRate\": \"68.9%\"}", "hints": [], "solution": { "id": "1995", "canSeeDetail": true, "paidOnly": false, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "status": null, "sampleTestCase": "{\"headers\":{\"Followers\":[\"user_id\",\"follower_id\"]},\"rows\":{\"Followers\":[[\"0\",\"1\"],[\"1\",\"0\"],[\"2\",\"0\"],[\"2\",\"1\"]]}}", "metaData": "{\"mysql\": [\"Create table If Not Exists Followers(user_id int, follower_id int)\"], \"mssql\": [\"Create table Followers(user_id int, follower_id int)\"], \"oraclesql\": [\"Create table Followers(user_id int, follower_id int)\"], \"database\": true, \"name\": \"count_followers\", \"pythondata\": [\"Followers = pd.DataFrame([], columns=['user_id', 'follower_id']).astype({'user_id':'Int64', 'follower_id':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Followers(user_id int, follower_id int)\"], \"database_schema\": {\"Followers\": {\"user_id\": \"INT\", \"follower_id\": \"INT\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Followers(user_id int, follower_id int)", "Truncate table Followers", "insert into Followers (user_id, follower_id) values ('0', '1')", "insert into Followers (user_id, follower_id) values ('1', '0')", "insert into Followers (user_id, follower_id) values ('2', '0')", "insert into Followers (user_id, follower_id) values ('2', '1')" ], "enableRunCode": true, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"
MySQL 8.0
.
mssql server 2019
.
Oracle Sql 11.2
.
Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0
\"], \"postgresql\": [\"PostgreSQL\", \"PostgreSQL 16
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }