[Python 3] Topological Sorting
\n\n\n```\n\ndef buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n        ans = [[0] * k for _ in 
\n\n\n```\n\ndef buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -> List[List[int]]:\n        ans = [[0] * k for _ in range(k)]\n\t\t\n        def topological(condition):\n            graph = defaultdict(list)\n            indegree = [0] * k\n            for a, b in condition:\n                graph[a].append(b)\n                indegree[b - 1] += 1\n            \n            que = deque()\n            for i, val in enumerate(indegree):\n                if val == 0:\n                    que.append(i + 1)\n                    \n            order = []\n            \n            while que:\n                temp = que.popleft()\n                order.append(temp)\n                \n                for child in graph[temp]:\n                    indegree[child - 1] -= 1\n                    if indegree[child - 1] == 0:\n                        que.append(child)\n                        \n            return order\n                        \n        row_order = topological(rowConditions)\n        col_order = topological(colConditions)\n        \n        #cycle detection\n        if len(row_order) < k or len(col_order) < k:\n            return []\n        \n        for row, val in enumerate(row_order):\n            col = col_order.index(val)\n            ans[row][col] = val\n            \n        return ans\n
['Topological Sort', 'Python3']