Kth Smallest Element in a BST

Medium Solved

Description

Given the root of a binary search tree, and an integer k, return the kth smallest value in the BST.

Input format / Clarification:

  • Line 1: BST as level-order JSON array (null for empty)
  • Line 2: Integer k

Examples

Input:

[3,1,4,null,2] 1

Output: 1

Input:

[5,3,6,2,4,null,null,1] 3

Output: 3

Note:

Your program must print only the integer result.

No submissions yet.

Discuss inorder traversal, recursion vs iteration, and BST properties.

Test Cases