Search
⌘K

Leetcode 2392. Build a Matrix With Conditions

Place numbers 1..k into a k×k grid (one per cell) so that given pairs enforce which number must appear in a strictly higher row or strictly more leftward column; return any valid matrix or empty if impossible. The core challenge is checking for cycles and deriving compatible row and column orders (via topological sort) and then mapping numbers to positions.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.