Hindi comments easy explanation | recursively travel to each child | tc = sc = O(N)
Intuition\n- Pehli baat jo dimaag mein aayi wo yeh thi ke tree traversal karna hai postorder mein. Pehle children process karne hain phir root ko. \n\n# Approac
# Intuition\n- Pehli baat jo dimaag mein aayi wo yeh thi ke tree traversal karna hai postorder mein. Pehle children process karne hain phir root ko. \n\n# Approach\nRecursive approach use karenge jisme har node ke liye **pehle uske saare children process karenge** phir us node ka value add karenge(null wali condition check karne ke baad). Ek helper function banayenge jo recursive call karega aur result ko ek vector mein store karega.\n\n# Complexity\n- Time complexity:\nTime complexity $$O(n)$$ hogi kyunki har node ko ek baar visit karna padega. \n\n- Space complexity:\nSpace complexity $$O(n)$$ hogi kyunki result store karne ke liye vector aur recursion ke liye stack space lagta hai. \n\n# Code\n```cpp []\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    vector<Node*> children;\n\n    Node() {}\n\n    Node(int _val) {\n        val = _val;\n    }\n\n    Node(int _val, vector<Node*> _children) {\n        val = _val;\n        children = _children;\n    }\n};\n*/\n\nclass Solution {\nprivate: \n    // Helper function \'f\' for recursion\n    void f(Node* &root, vector <int> &ans){\n        if (root == NULL) return; // Agar root NULL hai toh return kar do\n\n        for (auto child : root->children){ // Har child ke liye recursion\n            f(child, ans);\n            ans.push_back(child->val); // Child ka value add karo\n        }\n    }\n\npublic:\n    vector<int> postorder(Node* root) {\n        vector <int> ans;\n        f(root, ans);\n        if (root != NULL) ans.push_back(root->val); // Root ka value add karo agar root NULL nahi hai\n        return ans;\n    }\n};\n
['Tree', 'Recursion', 'C++']