Easy

Quiz

#501 Find Mode in Binary Search Tree

APPROACH

Given the root of a binary search tree (BST) with duplicates, return all the mode(s) — the most frequently occurring values. If multiple modes exist, return them in any order.

The BST is defined such that:

- The left subtree of a node contains only nodes with keys less than or equal to the node's key.

- The right subtree of a node contains only nodes with keys greater than or equal to the node's key.

- Both the left and right subtrees must also be binary search trees.

Example 1:

Input: root = [1,null,2,2]
Output: [2]

Example 2:

Input: root = [0]
Output: [0]
1 of 4
1:00

What is the optimal approach for this problem?