DAG Permissions IV
A DAG has n nodes, 0 to n - 1, and [parent, child] edges. allow[i] and deny[i] are strings of lowercase letters: the rules set directly on node i.
Both kinds of rule flow down to every descendant. A node's effective letters are every letter allowed on it or on any ancestor, minus every letter denied on it or on any ancestor — wherever an allow and a deny meet, the deny wins.
Return each node's effective letters as a sorted string ("" when it has none).
effectivePermissions(4, [[0, 1], [0, 2], [1, 3], [2, 3]], ["a", "b", "c", "d"], ["", "a", "b", ""]) -> ["a", "b", "ac", "cd"]
Node 3 inherits the allows a, b, c, d and the denies a, b, which leaves cd.
Hints
Hint 1
Two masks per node, both accumulated down the DAG with OR; the answer is one AND NOT at the end.
Hint 2
A topological order makes every parent's masks final before any child reads them.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.