Levels Below the Boss
staff has columns id and manager_id. One person, the boss, has manager_id None; everyone else's manager is in the table, and every chain of managers ends at the boss.
Return a dict from each id to how many levels below the boss that person is: 0 for the boss, 1 for people who report to the boss, and so on.
Example 1
staff {"id":[1,2,3,4,5],"manager_id":[null,1,1,2,4]}
returns {"1":0,"2":1,"3":1,"4":2,"5":3}
2 and 3 report to the boss. 4 reports to 2, and 5 reports to 4.
Constraints
1 <= len(staff) <= 40
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.