easy c++ sol |Kahn's Algo | Topological Sort | BFS | C++ | Short and Easy to Understand Code
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\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```\nclass Solution {\npublic:\n    vector<int> khan(int k,vector<vector<int>>& Conditions){\n     vector<int>graph[k+1];\n     vector<int>degree(k+1);\n     for(auto i:Conditions){\n        graph[i[0]].push_back(i[1]);\n        degree[i[1]]++;\n     }\n     queue<int>q;\n     for(int i=1;i<k;i++){\n        if(degree[i]==0){\n            q.push(i);\n        }\n     }\n     vector<int>ans;\n     while(!q.empty()){\n         int t=q.front();\n         q.pop();\n         ans.push_back(t);\n         for(auto i:graph[t]){\n            degree[i]--;\n            if(degree[i]==0){\n                q.push(i);\n            }\n         }\n     }\n\n    return ans;\n    }\n    vector<vector<int>> buildMatrix(int k, vector<vector<int>>& rowConditions, vector<vector<int>>& colConditions) {\n        vector<int>row=khan(k+1,rowConditions);\n        vector<int>col=khan(k+1,colConditions);\n        if(row.size()<k || col.size()<k){\n            return {};\n        }\n        unordered_map<int ,int>mp;\n        for(int i=0;i<k;i++){\n           mp[col[i]]=i;\n        }\n        vector<vector<int>>ans(k,vector<int>(k,0));\n        for(int i=0;i<k;i++){\n            int col_pos=mp[row[i]];\n            ans[i][col_pos]=row[i];\n        }\n        return ans;\n    }\n};\n```
['C++']