Medium
Quiz
#508 Most Frequent Subtree Sum
APPROACH
Given the root of a binary tree, compute the subtree sum for every node (the total of all values in the subtree rooted at that node, including itself). Return the subtree sum value(s) that appear most frequently. If multiple values share the top frequency, return all of them in any order.
Example 1:
Input: root = [5,2,-3]
Output: [2,-3,4]
Example 2:
Input: root = [5,2,-5]
Output: [2]
1 of 4
1:00
What is the optimal approach for this problem?