✅💯🔥Explanations No One Will Give You🎓🧠Very Detailed Approach🎯🔥Extremely Simple And Effective🔥
\n# Code\n\nclass Solution {\npublic:\n    vector<int> toposort(vector<vector<int>>& edges, int n) {\n        unordered_map<int, vector<int>> adj;\n        vect
\n# Code\n```\nclass Solution {\npublic:\n    vector<int> toposort(vector<vector<int>>& edges, int n) {\n        unordered_map<int, vector<int>> adj;\n        vector<int> indegree(n + 1, 0);\n        for (vector<int>& edge : edges) {\n            int u = edge[0];\n            int v = edge[1];\n            adj[u].push_back(v);\n            indegree[v]++;\n        }\n        queue<int> qu;\n        for (int i = 1; i <= n; i++) {\n            if (indegree[i] == 0) {\n                qu.push(i);\n            }\n        }\n        vector<int> topo;\n        int count = 0;\n        while (!qu.empty()) {\n            int u = qu.front();\n            qu.pop();\n            topo.push_back(u);\n            count++;\n            for (auto& it : adj[u]) {\n                indegree[it]--;\n                if (indegree[it] == 0) {\n                    qu.push(it);\n                    \n                }\n            }\n        }\n        if (count != n) {\n            return {};\n        }\n        return topo;\n    }\n\n    vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n        vector<vector<int>> matrix(k, vector<int>(k, 0));\n\n        vector<int> toposort_row = toposort(rowConditions, k);\n        vector<int> toposort_col = toposort(colConditions, k);\n\n        if (toposort_row.empty() || toposort_col.empty()) {\n            return {};\n        }\n\n        for(int i=0;i<k;i++)\n        {\n            for(int j=0;j<k;j++)\n            {\n                if(toposort_row[i]==toposort_col[j])\n                {\n                    matrix[i][j]=toposort_row[i];\n                }\n            }\n        }\n\n        return matrix;\n    }\n};\n\n```
['Graph', 'Topological Sort', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']