Mid From PDF Coding C# Coding Interview

Level-order traversal but return values in reverse order?

Short answer: List<List<int>> LevelOrderBottom(TreeNode root) {

Example code

var res = new List<List<int>>();
if (root == null) return res;
Queue<TreeNode> queue = new Queue<TreeNode>(); queue.Enqueue(root); while (queue.Count > 0) { int size = queue.Count;
var level = new List<int>(); Follow on: for (int i = 0; i < size; i++) {
TreeNode node = queue.Dequeue(); level.Add(node.val); if (node.left != null) queue.Enqueue(node.left);
if (node.right != null) queue.Enqueue(node.right);
} res.Insert(0, level); // prepend to get reverse order }
return res;
} Explanation: Perform normal BFS, insert each level at front of result list for reversed order.

Real-world example (ShopNest)

In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details