FastPrepTransitive Employee Referral Counts
Problems/Transitive Employee Referral Counts

Transitive Employee Referral Counts

Robinhood logoRobinhood● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a 45-minute onsite coding round as Employee Referral Counts but preserves no further statement. Counting transitive descendants in a referral forest is the most direct executable interpretation and matches the seed at about 74%.

Each string in referrals is referrer referredEmployee. The relationships form a forest: an employee has at most one direct referrer and no cycles occur.

For every employee mentioned in the input, count all direct and indirect referred descendants. Return employee=count strings sorted by employee id.

Function

referralCounts(referrals: String[]) → String[]

Examples

Example 1

referrals = ["A B","A C","B D"]return = ["A=3","B=1","C=0","D=0"]

A refers B and C directly and D through B.

Example 2

referrals = ["x y"]return = ["x=1","y=0"]

A leaf has no referred descendants.

Example 3

referrals = ["m n","p q"]return = ["m=1","n=0","p=1","q=0"]

Independent referral trees are both reported.

Constraints

  • 1 <= referrals.length <= 10^5.
  • Employee ids contain no spaces.
  • The directed relationships form a forest with no duplicate edges.

More Robinhood problems

  • Top Ten Most Frequent Words in a BookPHONE SCREEN · Seen Oct 2026
  • Fractional Share Inventory FlatteningPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Unique Transitive Dependent CountsPHONE SCREEN · Seen Sep 2026
All Robinhood interview questionsSee Robinhood hiring insights
Saved
class Solution {
    public String[] referralCounts(String[] referrals) {
        // Write your solution here.
    }
}
Checking account…