Solution: Build a Matrix with Conditions
Explore how to solve dependency constraints by performing topological sorts on row and column conditions. Understand how to detect cycles and map values to matrix positions, enabling you to build a matrix that satisfies strict ordering rules or determine when it's impossible.
We'll cover the following...
Statement
You are given a positive integer
A 2D integer array
rowConditionsof size, where rowConditions[i] = [above[i], below[i]]. This indicates thatabove[i]must appear in a row abovebelow[i]in the final matrix.A 2D integer array
colConditionsof size, where colConditions[i] = [left[i], right[i]]. This indicates thatleft[i]must appear in a column to the left ofright[i]in the final matrix.
Both arrays contain integers ranging from
You need to construct a