Find K-th Smallest Element in BST

Given a binary search tree (BST) and an integer K, the task is to find the K-th smallest element in the BST.

Example:

Input:
BST: Order of elements in increasing order is { 2, 3, 4, 5, 6, 7, 8, 10 }
K = 3
Output:
4
Explanation:

The 3rd smallest element in the BST is 4.

Constraints:

  • 1 <= T <= 100
  • 1 <= N, K <= 3000
  • -10^9 <= data <= 10^9
  • Time Limit: 1 sec
Note:
The input for the tree is provided in level order, using -1 for null nodes. The task is to find and return the K-th smallest element in the format described.
AnswerBot
4mo

To find the K-th smallest element in a BST, perform an in-order traversal and return the K-th element encountered.

  • Perform in-order traversal of the BST to get elements in increasing order

  • Keep track of...read more

Help your peers!
Select
Add answer anonymously...

Top Software Analyst Interview Questions Asked at Goldman Sachs

Q. Describe how to implement two stacks using a single array.
Q. Design a stack that supports push, pop, top, and retrieving the minimum element ...read more
Q. What is the difference between SQL and NoSQL databases?
Software Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits