Problem 3331 · Medium

Find Subtree Sizes After Changes

Each node moves under its nearest ancestor with the same letter; subtree sizes are then summed bottom-up, since parents always come earlier.

Open the interactive visualisation