As reported: D. E. Shaw online assessment for 2027 graduates (2026): a reporting tree of
Nemployees with employee 1 as the CEO; each employee is assigned to Core Systems or Quant Research so that, for every subtree, the counts of the two groups differ by at most 1; count the valid assignments modulo10^9 + 7.
A company's engineering hierarchy is a rooted tree of n employees; employee 1 (the CEO) is the root. Every employee is assigned to exactly one of two project groups: Core Systems or Quant Research.
Rule: for every employee, consider the whole team under them including themselves (their subtree). The numbers of people in Core Systems and in Quant Research in that team must differ by at most 1.
Return the number of valid assignments, modulo 10^9 + 7.
Example 1
n = 3, edges = [[1,2],[1,3]]
Output: 6
Each leaf is a team of one (always fine). The whole company of 3 must not be all in one group: 2^3 − 2 = 6.
Example 2
n = 4, edges = [[1,2],[2,3],[3,4]]
Output: 4
A chain: the team under employee 3 (employees 3 and 4) must be split 1–1, and so must the whole company.
Constraints: 1 ≤ n ≤ 2 · 10^5; edges has n − 1 pairs [u, v] (1-based, undirected) forming a tree.
Code runner format: one JSON value per line: n, then edges. Implement countAssignments(n, edges).