As reported: Rubrik software engineer interview for 2027 graduates (2026), one coding problem.
N servers form a rooted dependency tree; server 1 is the root. Server i has a positive integer A[i].
A backup chain is any downward path from a server to one of its descendants, possibly the server itself (a single server is a chain). A chain is stable if the product of A over the servers on it is a perfect square.
Count the stable backup chains.
Example 1
values = [2,8,3,3,1], parent = [0,1,2,1,4] -> 2
Edges 1–2, 2–3, 1–4, 4–5. Stable chains: 1→2 (2·8 = 16) and 5 alone (1).
Example 2
values = [4], parent = [0] -> 1
Constraints: 1 ≤ N ≤ 10^6; 1 ≤ A[i] ≤ 100.
Code runner format: two lines — values (values[i-1] = A[i]) and parent (parent[i-1] is the parent of server i, 0 for the root), as JSON arrays. Implement countStableChains(values, parent); the harness prints the count (it can exceed 32 bits).