
Asked in Goldman Sachs
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!
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?
Interview Questions Asked to Software Analyst at Other Companies
Top Skill-Based Questions for Goldman Sachs Software Analyst
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

