Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5594
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3412
Postorder Traversal (Iterative)
Medium Accuracy: 87.44% Submissions: 1314 Points: 4

Given a binary tree. Find the postorder traversal of the tree without using recursion.

Example 1

Input:
1
/   \
2     3
/  \
4    5

Output: 4 5 2 3 1
Explanation:
Postorder traversal (Left->Right->Root) of
the tree is 4 5 2 3 1.


Example 2

Input:
8
/      \
1          5
\       /   \
7     10    6
\   /
10 6

Output: 10 7 1 6 10 6 5 8
Explanation:
Inorder traversal (Left->Right->Root)
of the tree is 10 7 1 6 10 6 5 8 .

You don't need to read input or print anything. Your task is to complete the function postOrder() which takes the root of the tree as input and returns a list containing the postorder traversal of the tree, calculated without using recursion.

Expected time complexity: O(N)
Expected auxiliary space: O(N)

Constraints:
1 <= Number of nodes <= 105
1 <= Data of a node <= 105