Can anyone tell why I am getting TLE here?
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nUsed positive & negative arrays to calculate the coins to be places. Igno
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nUsed positive & negative arrays to calculate the coins to be places. Ignore the cout as it was used while debugging. But I cant understand why I am getting TLE here? \nThe soln goes to each node once only. \n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    unordered_set<int> visited;\n    void fillArrsHelper(int idx, int root, int rootCost, vector<vector<int>> &topThree, vector<vector<int>> &bottomThree) {\n        vector<int> posArr;\n        cout<<root<<" "<<idx<<endl;\n        cout<<"printing : "<<endl;\n        vector<int> negArr;\n        for (int i=0; i<3; i++) {\n            posArr.push_back(topThree[idx][i]);\n            posArr.push_back(topThree[root][i]);\n        }\n\n        for (int i=0; i<3; i++) {\n            negArr.push_back(bottomThree[idx][i]);\n            negArr.push_back(bottomThree[root][i]);\n        }\n\n        \n        sort(posArr.begin(), posArr.end(), greater<int> ());\n        sort(negArr.begin(), negArr.end());\n\n        for (int i=0; i<3; i++) {\n            topThree[root][i] = posArr[i];\n            cout<<topThree[root][i]<<"  ";\n        }\n        cout<<endl;\n\n        for(int i=0; i<3; i++) {\n            bottomThree[root][i] = negArr[i];\n            cout<<bottomThree[root][i]<<"  ";\n        }\n        cout<<endl;\n        \n        return;\n    }\n\n    void fillArrs(int root, vector<vector<int>> &graph, vector<vector<int>> &topThree, vector<vector<int>> &bottomThree, vector<int> &cost) {\n        if(visited.find(root) != visited.end()) {\n            return;\n        }\n        visited.insert(root);\n        cout<<"ROOT :"<<root<<endl;\n        if (cost[root] <0) {\n            bottomThree[root][0]=(cost[root]);\n        }else {\n            topThree[root][0]=(cost[root]);\n        }\n        for(int i=0; i<graph.size(); i++) {\n            if (graph[root][i] == 1 && root != i && visited.find(i) == visited.end()) {\n                fillArrs(i, graph, topThree, bottomThree, cost);\n                fillArrsHelper(i, root, cost[root], topThree, bottomThree);\n            }\n        }\n\n        if (topThree[root][0] == INT_MIN && bottomThree[root][0] == INT_MAX) {\n            // cout<<"leaf : "<<endl;\n            if (cost[root] >=0) {\n                topThree[root][0] = cost[root];\n            }else {\n                bottomThree[root][0] = cost[root];\n            }\n        }\n        \n\n        // for(int i=0; i<3; i++) {\n        //     cout<<topThree[root][i]<<" ";\n        // }\n\n        // for(int i=0; i<2; i++) {\n        //     cout<<bottomTwo[root][i]<<" ";\n        // }\n        // cout<<endl;\n    }\n        \n    \n    vector<long long> placedCoins(vector<vector<int>>& edges, vector<int>& cost) {\n        int n = edges.size()+1;\n        vector<vector<int>> graph(n, vector<int>(n,0));\n        for(int i=0; i<edges.size(); i++) {\n            int from = edges[i][0];\n            int to = edges[i][1];\n            graph[from][to] = 1; \n            graph[to][from] = 1;\n        }\n        vector<vector<int>> topThree(n, vector<int>(3, INT_MIN));\n        vector<vector<int>> bottomThree(n, vector<int>(3, INT_MAX));\n\n        fillArrs(0, graph, topThree, bottomThree, cost);\n        vector<long long> ans(n, 0);\n       cout<<"***************8888"<<endl;\n       for(int i=0; i<n; i++) {\n        int top1 = topThree[i][0];\n        int top2 = topThree[i][1];\n        int top3 = topThree[i][2];\n\n        int bottom1 = bottomThree[i][0];\n        int bottom2 = bottomThree[i][1];\n        int bottom3 = bottomThree[i][2];\n        int count = 0;\n        if (top1 != INT_MIN) {\n            count++;\n        }\n        if (top2 != INT_MIN) {\n            count++;\n        }\n        if (top3 != INT_MIN) {\n            count++;\n        }\n        if (bottom1 != INT_MAX) {\n            count++;\n        }\n        if (bottom2 != INT_MAX) {\n            count++;\n        }\n\n        if(bottom3 != INT_MAX) {\n            count++;\n        }\n\n        cout<<"i :"<<i<<" top : "<<top1<<" "<<top2<<" "<<top3<<"  bottom : "<<bottom1<<" "<<bottom2<<endl;\n        if (count <3) {\n            ans[i] = 1;\n        }\n        else if (top1 != INT_MIN && top2 != INT_MIN && top3 != INT_MIN) {\n           \n            ans[i] = (long long)top1*top2*top3;\n            if(bottom1 != INT_MAX && bottom2 != INT_MAX) {\n                long long secondAns = (long long)top1*bottom1*bottom2;\n                if (secondAns > ans[i]) {\n                    ans[i] = secondAns;\n                }\n            }\n        }else if (top1 != INT_MIN && bottom1 != INT_MAX && bottom2 != INT_MAX) {\n            ans[i] = (long long) top1*bottom1*bottom2;\n        }\n        else{\n            ans[i] = 0;\n        \n        }\n       }\n        return ans;\n    }\n};\n```
['C++']