Identify the Influencer Everyone Follows but Who Follows Nobody

Last updated: November 29, 2026

Quick Overview

Among n members, an influencer is followed by all other n - 1 members and follows none of them. Using only an API follows(a, b), return the influencer's id or -1, making O(n) calls.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Among n members, an influencer is followed by all other n - 1 members and follows none of them. Using only an API follows(a, b), return the influencer's id or -1, making O(n) calls.

The LinkedIn follow graph makes this classic elimination question feel natural, and the API-call budget is the real test. Interviewers check the elimination argument and the verification pass that many candidates forget.

What the Interviewer Expects
  • Explains that each follows(a, b) call eliminates one candidate
  • Runs a single elimination pass to find one candidate
  • Verifies the candidate with a second pass
  • Keeps calls at most 3(n - 1)
  • Handles the no-influencer case
Key Topics to Cover
graph
elimination
API call budget
two pass
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Can you reduce calls in the verification pass by reusing elimination results?
  • What if follows is an expensive remote call and you can batch requests?
  • How would you find all members followed by at least 90% of others?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Members are 0..n-1. follows(a, b) returns True if a follows b. There is at most one influencer (two cannot exist because they would have to follow each other). Return the id or -1....

High-Level Design

Elimination: keep a candidate c, starting at 0. For each i from 1, if follows(c, i), then c follows someone and is out, so set c = i; otherwise i is not followed by c, so i is out. After one pass, e...


Submit Your Answer
Markdown supported