You are given a tree where each node has a color. For each node, find the sum of all colors that appear most frequently in its subtree. If multiple colors tie for max frequency, sum all of them. This requires tracking color counts and identifying the maximum count at each node.
Small-to-large merging lets you maintain a frequency map per subtree efficiently. I'll show you how to extend the technique from sets to maps.