911. Iterative Postorder Using One Stack

MediumTreesBinary TreeStackTraversal

Given the root of a binary tree, return its postorder traversal computed iteratively using a single explicit stack (no recursion). Return the values as an array. The tree is given as a level-order array with null for missing children.

Input: A level-order array of the tree.

Output: Array — node values in postorder.

Examples

Example 1
Input: [1,2,3,4,5,null,7]
Output: [4,5,2,7,3,1]
Explanation: Left, right, root order.
Example 2
Input: [1]
Output: [1]
Explanation: Single node.
Example 3
Input: []
Output: []
Explanation: Empty tree.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →