Tap here to switch tabs
Problem
Submissions

Problem: Median of a Binary Search Tree Level

Median of a Binary Search Tree Level asks you to find the median of values at a requested level, with the root at level zero. Use the larger middle value for even counts, or minus one if empty.

Statement

Given the root of a binary search tree and an integer level, return the median value of all node values located at that level.

If the number of nodes at the specified level is even, return the larger of the two middle values after sorting. If no nodes exist at the given level, return −1-1.

Note: The root of the tree is located at level 00.

Constraints:

  • The number of nodes in the tree is in the range [1,2imes105][1, 2 imes 10^5].

  • 1≤1 \leq Node.val ≤106\leq 10^6

  • 0≤0 \leq level ≤2imes105\leq 2 imes 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Median of a Binary Search Tree Level

Median of a Binary Search Tree Level asks you to find the median of values at a requested level, with the root at level zero. Use the larger middle value for even counts, or minus one if empty.

Statement

Given the root of a binary search tree and an integer level, return the median value of all node values located at that level.

If the number of nodes at the specified level is even, return the larger of the two middle values after sorting. If no nodes exist at the given level, return −1-1.

Note: The root of the tree is located at level 00.

Constraints:

  • The number of nodes in the tree is in the range [1,2imes105][1, 2 imes 10^5].

  • 1≤1 \leq Node.val ≤106\leq 10^6

  • 0≤0 \leq level ≤2imes105\leq 2 imes 10^5