Search
⌘K

Leetcode 1916. Count Ways to Build Rooms in an Ant Colony

Given a rooted tree (parent array) where you can build a room only after its parent and you can move only along already-built edges, count the number of valid build orders to construct all rooms modulo 1e9+7. This reduces to computing how to interleave builds of each node's child subtrees — the answer is the product of multinomial coefficients based on subtree sizes, computable via a DFS with precomputed factorials/inverses.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.