threeal / leetspace

A dedicated workspace and archive for my LeetCode submissions
https://leetcode.com/threeal
MIT License
1 stars 1 forks source link

Solve Problem 2392. Build a Matrix With Conditions #1380

Open threeal opened 1 month ago

threeal commented 1 month ago

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.