Non-Recursive Tree Navigation
In this problem you need to find all elements at a given level in a BST. I realized that unfortunately my solution doesn't take into account the BST property, hence in order to make it slightly faster (as a compromise), I decided to navigate the tree using a Stack. Runs in NLogN which still makes the cut. Code is down below, cheers, ACC. Median of a Binary Search Tree Level - LeetCode You are given the root of a Binary Search Tree (BST) and an integer level . The root node is at level 0. Each level represents the distance from the root. Return the median value of all node values present at the given level . If the level does not exist or contains no nodes, return -1. The median is defined as the middle element after sorting the values at that level in non-decreasing order. If the number of values at that level is even, return the upper median (the larger of the two middle elements after sorting). ...