Build a Matrix with Conditions
Try to solve the Build a Matrix with Conditions problem.
We'll cover the following
Statement
You are given a positive integer
A 2D integer array
rowConditions
of size, where rowConditions[i] = [above[i], below[i]]
. This means thatabove[i]
must appear in a row abovebelow[i]
in the final matrix.A 2D integer array
colConditions
of size, where colConditions[i] = [left[i], right[i]]
. This means thatleft[i]
must appear in a column to the left ofright[i]
in the final matrix.
Both arrays contain integers from
Your task is to build a
The matrix should also satisfy the following conditions:
For each
from to , the integer above[i]
must appear in a row strictly abovebelow[i]
.For each
from to , the integer left[i]
must appear in a column strictly to the left ofright[i]
.
Return any matrix that meets these conditions. If no valid matrix exists, return an empty matrix.
Constraints:
rowConditions.length
,colConditions.length
rowConditions[i].length
colConditions[i].length
above[i]
,below[i]
,left[i]
,right[i]
above[i]
below[i]
left[i]
right[i]
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.