PPractick

DSA interview question

Binary Tree Postorder Traversal

Easy · Data structures · Topics: tree, dfs, recursion

The problem

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].

Function signature

vector<int> postorderTraversal(TreeNode* root);

Test cases

Input (level order)OutputExplanation
[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.)

How interviewers phrase it

Clarifying questions to ask

  1. Recursive or iterative?
  2. How deep can the tree be?
  3. What should an empty tree return? (An empty list.)

Follow-ups to expect

  1. "Why is postorder the natural order for deletion or size computation?"
  2. "Iterative with two stacks?"
  3. "Iterative with one stack?"
  4. "How does postorder relate to preorder?"
  5. "Complexity?"

Practise questions like this with a real engineer

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 interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in