Second Degree Follower
A medium-tier problem at 40% community acceptance, tagged with Database. Reported in interviews at Databricks and 0 others.
Second Degree Follower is a database problem that shows up in real technical assessments, and Databricks has asked it. The 40% acceptance rate tells you most candidates either misread the schema or write an inefficient join. You're being asked to traverse a two-level relationship in a SQL table, find indirect connections, and filter them correctly. The trick is handling self-joins without accidentally counting duplicates or including direct followers. If this problem hits your live assessment and you blank on the schema traversal, StealthCoder runs invisibly during screen share and surfaces a working query in seconds.
Companies that ask "Second Degree Follower"
Second Degree Follower is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe problem requires you to find second-degree followers: people who follow someone who follows a target user. The naive approach is a single self-join on a followers table, but most candidates botch it by not excluding direct followers or by creating the wrong join condition. You need to join the followers table to itself carefully. If user A follows B and B follows C, then C is a second-degree follower of A. The trap is forgetting to filter out cases where A directly follows C as well, or mixing up which columns alias to which user IDs. A second trap: the order of joins and the WHERE clause filtering. Write it wrong and you get duplicates or missing results. This is exactly the kind of problem where you nail the schema in an interview or you don't. StealthCoder handles the alias logic and join cardinality so you don't have to second-guess yourself mid-assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Second Degree Follower recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Second Degree Follower interview FAQ
Why is the acceptance rate so low on this problem?+
Self-joins trip up most candidates. The issue is keeping track of which table alias represents which user level, and correctly excluding direct followers from the second-degree result set. Most candidates write a join that's logically close but produces duplicates or wrong row counts.
Is this still asked at companies like Databricks?+
Yes. Databricks and similar data-heavy companies ask SQL relationship problems regularly. They want to see if you can construct multi-table queries without assistance. The schema is simple but the join logic reveals how you think.
What's the exact trick to avoid double-counting?+
You need to exclude rows where the first-degree follower directly follows the target user. Use a NOT IN or NOT EXISTS subquery, or join three times and filter out direct edges. Most people miss this and get false results.
How does this relate to graph traversal in general?+
This is SQL's way of doing depth-limited graph traversal. You're moving exactly two hops in a directed graph. Harder problems add more hops or require recursion, but this one is pure join logic.
Can I solve this without a subquery?+
Yes. A double self-join with careful WHERE clause filtering works fine. Join followers twice, alias the tables clearly, and exclude cases where the target follows the result directly. Some solutions are more readable than others, but a single query without subqueries is possible.
Want the actual problem statement? View "Second Degree Follower" on LeetCode →