A sensor tree allows repeated values. It is a search tree in the relaxed sense: every value in a node's left subtree is less than or equal to the node, and every value in its right subtree is greater than or equal to it. Return all values that occur most often (the modes), in any order. Return [] for an empty tree.
Examples
6
/ \
6 9
/ / \
2 9 9
Input: root = build_tree([6, 6, 9, 2, None, 9, 9])
Output: [9] (9 appears three times)
4
/ \
2 4
/
2
Input: root = build_tree([4, 2, 4, 2])
Output: [2, 4] (both appear twice; any order)
Constraints
0 <= number of nodes <= 3000- Try to use O(h) extra space besides the answer (no dictionary of counts)
Goals
- Use the sorted inorder order to count runs of equal values
- Collect every value tied for the highest count