Find cost center leaders
A people directory draws an org chart from a flat roster. names holds one person per entry, and manager_of has the same length: entry i is the position of the person that person i reports to, or -1 for the single person at the top. The roster arrives in no particular order, so a manager can sit at a later position than the people reporting to them. Nobody reports to two managers and the chart never loops. Finance wants the leaders whose organization is big enough to earn its own cost center. A person's organization is everyone below them at any depth, direct reports plus their reports and onward, not counting the person. Return the names of the people whose organization holds at least min_reports people, in the order those people appear in names. An empty roster returns an empty list.
managers_over_headcount(names: list[str], manager_of: list[int], min_reports: int) → list[str][["Ada","Bo","Cy","Di","Eli"],[-1,0,0,1,1],2]out["Ada","Bo"][["rita","sam","tom"],[2,2,-1],1]out["tom"]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["Ada","Bo","Cy","Di","Eli"],[-1,0,0,1,1],2]["Ada","Bo"]not run yetsample[["rita","sam","tom"],[2,2,-1],1]["tom"]not run yetsample