shlogg · Early preview
Md Ariful Haque @mah-shamim

Build Matrix With Conditions In PHP

Build a k x k matrix satisfying row and column conditions using topological sorting and graph theory.

2392. Build a Matrix With Conditions
Hard
You are given a positive integer k. You are also given:

a 2D integer array rowConditions of size n where rowConditions[i] = [abovei, belowi], and
a 2D integer array colConditions of size m where colConditions[i] = [lefti, righti].

The two arrays contain integers from 1 to k.
You have to build a k x k matrix that contains each of the numbers from 1 to k exactly once. The remaining cells should have the value 0.
The matrix should also satisfy the following conditions:

The number abovei should appear in a row that is strictly above the row at which the...