As reported: Cohesity Software Engineer, round 1 (DSA, 60 minutes), 2026. Directed edges describe a database replication hierarchy; each node is a replica. A replica can be deleted only after all of its child replicas are deleted; deleting replica
itakesdeletionTime[i]; replicas that do not depend on each other can be deleted in parallel. Find the minimum total time to delete the whole tree.
There are n replicas numbered 0 to n - 1. edges[j] = [parent, child] means replica child replicates from replica parent. The edges form one rooted tree: exactly one replica (the root) has no parent, and every other replica has exactly one parent.
Deleting replica i takes deletionTime[i] units of time. A replica's deletion can start only when all of its children have been fully deleted. Any number of deletions may run at the same time.
Return the minimum time after which every replica has been deleted.
Example 1
n = 5, edges = [[0,1],[0,2],[1,3],[1,4]], deletionTime = [2,4,3,1,5]
Output: 11
Replicas 3, 4 and 2 are leaves and start at time 0. Replica 1 waits for 3 (done at 1) and 4 (done at 5), so it runs from 5 to 9. Replica 0 waits for 1 (done at 9) and 2 (done at 3), so it runs from 9 to 11.
Example 2
n = 4, edges = [[2,0],[2,1],[0,3]], deletionTime = [3,1,2,6]
Output: 11
The root is replica 2. The chain 3 → 0 → 2 takes 6 + 3 + 2 = 11.
Example 3
n = 1, edges = [], deletionTime = [7]
Output: 7
Constraints: 1 <= n <= 10^5, edges.length == n - 1, 0 <= parent, child < n, the edges form a single rooted tree (the root is not necessarily replica 0), 1 <= deletionTime[i] <= 10^4. The tree can be a single chain of n replicas.
Code runner format: one JSON value per line: n, edges, deletionTime. Implement minDeletionTime(n, edges, deletionTime) returning the minimum total time (a 64-bit integer in Java, C++ and Go).