n employees numbered 0 to n - 1, where n = len(links) + 1. Each pair [a, b] in links is a manager–report link, but it does not say which of the two is the boss. All you know is that employee 0 is at the top and the links form a tree.
A *branch* of an employee is one direct report together with everyone below that report. An employee has an *evenly split team* if all of their branches have the same size. Anyone with no reports or a single report counts as evenly split.
Return the number of employees with an evenly split team.links=[[0, 1], [0, 2], [1, 3], [2, 4]] → 5
Employee 0 has two branches of 2 people each, 1 and 2 have a single report each, and 3 and 4 have none. All five qualify.
links=[[0, 1], [0, 2], [2, 3]] → 3
Employee 0's branches are {1} and {2, 3}, sized 1 and 2, which differ. The other three qualify, so the answer is 3.
links=[[1, 0]] → 2
links=[[0, 1], [0, 2], [1, 3], [2, 4]]
5
Run checks the first 3 tests in your browser. Submit checks all 49 tests on the server, hidden ones included.