Easy Intuition||TOPO SORT||
Intuition\nsince we have given the boundations like this should appear first than this like these.... so we can directly think of topological sort and then afte
# Intuition\nsince we have given the boundations like this should appear first than this like these.... so we can directly think of topological sort and then after getting order for row and column we can just use map to decide the actual row and column  \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\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```cpp []\nclass Solution {\npublic:\n    vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n        unordered_map<int,list<int>>mp1;\n        unordered_map<int,list<int>>mp2;\n        vector<int>indegree1(k+1,0);\n        vector<int>indegree2(k+1,0);\n\n        for(int i=0;i<rowConditions.size();i++){\n            mp1[rowConditions[i][0]].push_back(rowConditions[i][1]);\n            indegree1[rowConditions[i][1]]++;\n        }\n         for(int i=0;i<colConditions.size();i++){\n            mp2[colConditions[i][0]].push_back(colConditions[i][1]);\n            indegree2[colConditions[i][1]]++;\n        }\n        vector<int>ans1;\n        vector<int>ans2;\n        queue<int>q1,q2;\n\n        for(int i=1;i<indegree1.size();i++){\n            if(indegree1[i]==0){\n                q1.push(i);\n            }\n        }\n          for(int i=1;i<indegree2.size();i++){\n            if(indegree2[i]==0){\n                q2.push(i);\n            }\n        }\n        while(!q1.empty()){\n            int element=q1.front();\n            q1.pop();\n            ans1.push_back(element);\n            for(auto it:mp1[element]){\n                indegree1[it]--;\n                if(indegree1[it]==0){\n                    q1.push(it);\n                }\n            }\n        }\n         while(!q2.empty()){\n            int element=q2.front();\n            q2.pop();\n            ans2.push_back(element);\n            for(auto it:mp2[element]){\n                indegree2[it]--;\n                if(indegree2[it]==0){\n                    q2.push(it);\n                }\n            }\n        }\n\n        // for(int i=0;i<ans2.size();i++){\n        //     cout<<ans2[i]<<" ";\n        // }\n        vector<vector<int>>ans;\n        if(ans1.size()<k || ans2.size()<k){\n          return ans;\n        }\n        unordered_map<int,int>row,col;\n        for(int i=0;i<ans1.size();i++){\n            row[ans1[i]]=i;\n        }\n        for(int i=0;i<ans2.size();i++){\n            col[ans2[i]]=i;\n        }\n        vector<vector<int>>final1(k,vector<int>(k,0));\n        for(int i=1;i<=k;i++){\n            final1[row[i]][col[i]]=i;\n        }\n        return final1;\n    }\n};\n```
['C++']