Back to problems

Kth Smallest Element in a Binary Search Tree (write full main, with follow-ups)

Algorithm · Microsoft · Medium

Given a Binary Search Tree (BST) root and an integer k, determine the value that ranks k-th in ascending order among every node in the tree, using 1-based indexing. Input (stdin) First line: The tree encoded as a level-order array, where absent children are written as null; for example, [7,3,9,1,5] Second line: The integer k Output (stdout) Print one integer: the value that is the k-th smallest in the BST Constraints The tree contains n nodes, where 1 <= n <= 2 * 10^5 1 <= k…

Checking your access…