DSA interview question
A contacts app stores names in a binary search tree, and its "show all, sorted" button walks the tree inorder: left subtree, then the node, then the right subtree. For a BST that visits the keys in sorted order, and for any binary tree it gives the natural "left to right" reading of the nodes. The recursive version mirrors the definition directly.
Example: [1, null, 2, 3] → [1, 3, 2].
vector<int> inorderTraversal(TreeNode* root);
| Input (level order) | Output | Explanation |
|---|---|---|
[1, null, 2, 3] | [1, 3, 2] | |
[1, 2, 3, 4, 5, null, 8, null, null, 6, 7, 9] | [4, 2, 6, 5, 7, 1, 3, 9, 8] | |
[2, 1, 3] | [1, 2, 3] | A BST comes out sorted |
[] | [] | |
[1] | [1] |
(Confirm: LeetCode's level-order input format; the tree may be empty.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in