Since there is no minimum size for the matrix, one can build a matrix where there is exactly one value for each row and column, as in example 1. To achieve this, one needs to build a topological sort for numbers from 1 to k for both columns and rows using the given conditions. If there is a cycle in the conditions, return early with an empty matrix.
This issue suggests solving the problem 2392. Build a Matrix With Conditions.
Since there is no minimum size for the matrix, one can build a matrix where there is exactly one value for each row and column, as in example 1. To achieve this, one needs to build a topological sort for numbers from 1 to
k
for both columns and rows using the given conditions. If there is a cycle in the conditions, return early with an empty matrix.