DSA interview question
A disk-usage tool computes the size of every folder, and a folder's size is only known after all its subfolders have been measured. Processing children before their parent is postorder: left subtree, right subtree, then the node. The same pattern appears when deleting a tree (free the children before the parent) and when evaluating expression trees (evaluate the operands before applying the operator).
Example: [1, null, 2, 3] → [3, 2, 1].
vector<int> postorderTraversal(TreeNode* root);
| Input (level order) | Output | Explanation |
|---|---|---|
[1, null, 2, 3] | [3, 2, 1] | |
[1, 2, 3, 4, 5, null, 8, null, null, 6, 7, 9] | [4, 6, 7, 5, 2, 9, 8, 3, 1] | |
[2, 1, 3] | [1, 3, 2] | |
[] | [] | |
[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