# LeetCode: Kth Smallest Element in a BST Solution

Inorder traversal

## Approach

Get the k-th element from result of inorder traversal

## Implementation

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}var kthSmallest = function (root, k) {2  const traversed = []3
4  const recursion = node => {5    if (!node) return6    recursion(node.left)7    traversed.push(node.val)8    recursion(node.right)9  }10
11  recursion(root)12
13  return traversed[k - 1]14}```

Original problem

## Similar problems

Binary Tree Inorder Traversal

Second Minimum Node In a Binary Tree

## Tags

leetcode

tree

binary tree

binary search tree

dfs

recursion

## Next Post

LeetCode: Path Sum III

Sep 9, 2022

If timebox exceeded, read other solutions

## Previous Post

LeetCode: Diameter of Binary Tree

Sep 5, 2022

Sum of max height of 2 subtrees

Search Posts