A bundler describes how to build an app as a binary tree of targets. A target can only be built after both of its sub-targets (left and right) are built. The bundler always builds the whole left side before the right side.
Write buildSteps(root) that returns the target ids in the order they get built: postorder, meaning the left subtree, then the right subtree, then the node. Don't use recursion, because the tree can be very deep. An empty tree returns [].
Input: root = [1,2,3,4,5] Output: [4,5,2,3,1]
2 needs 4 and 5 first, and the root 1 comes last.
Input: root = [1,null,2,3] Output: [3,2,1]
3 must be built before 2, and 2 before 1.
0 <= number of targets <= 100000Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #330 Postorder Build Steps. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.