Dsa
Binary Search Tree
Warm-up
Collect Nodes in Level Order
You are given the root of a binary search tree (BST). Your task is to collect the values of the nodes in level order (breadth-first search) and return them as a list.
Input Format:
- The first line contains an integer n, the number of nodes in the BST.
- The next n lines each contain a single integer, which represents the value of the node inserted into the BST.
Output Format:
- Print a list of integers representing the level order traversal of the BST.
Example:
Input:
4
5
3
7
6
Output:
[5, 3, 7, 6]
Key concepts
binary_search_treelevel_order_traversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now