Search
⌘K

Leetcode 3331. Find Subtree Sizes After Changes

Given a rooted tree with a character on each node, simultaneously reparent every node (except the root) to its nearest ancestor that has the same character (if any), producing a modified tree. Return the sizes of all subtrees in that final tree — the core challenge is efficiently finding nearest same-letter ancestors for all nodes and computing subtree sizes under n up to 1e5.


Question Timeline

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

Comments

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