Easy - Topological sort!!
When we here something should come before something then ---->\nTopo Sort --> Intuition\n# Complexity\n- Time complexity:\nBFS - O(2(k+E)) --> E --> no of edges
When we here something should come before something then ---->\nTopo Sort --> Intuition\n# Complexity\n- Time complexity:\nBFS - O(2(k+E)) --> E --> no of edges --> 2 time topo sort\nO(2(k+E)) + O(k^2)\n\n- Space complexity:\nIn topo sort --> O(k)\n\n//k is like number of nodes\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> topoSort(int k,vector<int>adj[]){\n        vector<int>indegree(k+1,0);\n        for(int i = 1;i<=k;++i){\n            for(auto it:adj[i]){\n                indegree[it]++;\n            }\n        }\n        \n        queue<int>q;\n        vector<int>topo;\n        for(int i = 1;i<=k;++i){\n            // cout<<indegree[i]<<" ";\n            if(indegree[i]==0){\n                q.push(i);\n            }\n        }\n        // cout<<"\\n";\n        while(!q.empty()){\n            int node = q.front();\n            q.pop();\n            topo.push_back(node);\n            for(auto it:adj[node]){\n                indegree[it]--;\n                if(indegree[it]==0){\n                    q.push(it);\n                }\n            }\n        }\n        return topo;\n    }\n    vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, \n    vector<vector<int>>& colConditions) {\n        vector<vector<int>>ans(k,vector<int>(k,0));\n        vector<int>adjR[k+1];\n        vector<int>adjC[k+1];\n        for(auto it:rowConditions){\n            adjR[it[0]].push_back(it[1]);\n        }\n        for(auto it:colConditions){\n            adjC[it[0]].push_back(it[1]);\n        }\n        vector<int>topo1 = topoSort(k,adjR);\n        vector<int>topo2 = topoSort(k,adjC);\n\n        // cout<<topo1.size()<<" "<<topo2.size()<<"\\n";\n        if(topo1.size()!=k || topo2.size()!=k){\n            return {};\n        }\n        // for(auto it:topo1) cout<<it<<" ";\n        for(int i = 0;i<k;++i){\n            for(int j = 0;j<k;++j){\n                if(topo1[i]==topo2[j]){\n                    ans[i][j] = topo1[i];\n                }\n            }\n        }\n        return ans;\n    }   \n};\n```
['C++']