LeetCode - Blind 75 - Kth Smallest Element in a BST

The Problem Given the root of a binary search tree and an integer k, return the kth smallest value (1-indexed) among all the values of the nodes in the tree. Examples Input: root = [3,1,4,null,2], k = 1 Output: 1 Input: root = [5,3,6,2,4,null,null,1], k = 3 Output: 3 Constraints The number of nodes in the tree is n. 1 <= k <= n <= 10⁴ 0 <= Node.val <= 10⁴ Follow-up: If the BST is modified often (i.e., we can perform insert and delete operations) and you need to find the kth smallest element frequently, how would you optimize? ...

January 20, 2025 · 2 min · Dmytro Chumakov