Dsa
Binary Search Tree
Hard
Level Order BST Serialization
Implement a function that serializes a binary search tree into a level-order formatted string. Each level of the tree should be represented by square brackets and levels should be separated by commas. The input format consists of several lines: the first line contains an integer n (the number of nodes), followed by n lines which contain the values for each node. Print the serialized level-order representation. Example input/output is shown below.
Input:
5
10
5
15
3
7
Output:
[10], [5, 15], [3, 7]
Key concepts
binary_search_treeserializationlevel_order
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