Free written solution

Most Frequent Subtree Sum (LeetCode 508): Solution and Explanation

Every node defines a subtree, and every subtree has a sum. Return the sum that shows up most often across all nodes, or every sum that ties for the top count.

Read the intuition, approach, code and complexity →