So i implemented this using stack and got AC, however my queue solution fails for a test case…

```
class Solution {
public:
vector<int> postorder(Node* root) {
if(root==NULL) return {};
vector<int> res;
queue<Node*> stk;
stk.push(root);
while(!stk.empty())
{
Node* temp=stk.front();
stk.pop();
for(int i=temp->children.size()-1;i>=0;i--) stk.push(temp->children[i]);
res.push_back(temp->val);
}
reverse(res.begin(), res.end());
return res;
}
};
```

Fails for:

Output:

[14,11,12,13,6,7,8,9,10,2,3,4,5,1]

Expected:

[2,6,14,11,7,3,12,8,4,13,9,10,5,1]

Accepted stack approach:

```
class Solution {
public:
vector<int> postorder(Node* root) {
if(root==NULL) return {};
vector<int> res;
stack<Node*> stk;
stk.push(root);
while(!stk.empty())
{
Node* temp=stk.top();
stk.pop();
for(int i=0;i<temp->children.size();i++) stk.push(temp->children[i]);
res.push_back(temp->val);
}
reverse(res.begin(), res.end());
return res;
}
};
```