MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / buildMatrix

Method buildMatrix

BuildAMatrixWithConditions.java:50–69  ·  view source on GitHub ↗
(int k, int[][] rowConditions, int[][] colConditions)

Source from the content-addressed store, hash-verified

48 return ans;
49 }
50 public int[][] buildMatrix(int k, int[][] rowConditions, int[][] colConditions) {
51 int rowToposort[] = topoSort(k, rowConditions);
52 if(rowToposort.length==0){
53 return new int[0][0];
54 }
55 int colToposort[] = topoSort(k, colConditions);
56 if(colToposort.length==0){
57 return new int[0][0];
58 }
59 int matrix[][] = new int[k][k];
60 for(int i=0;i<k;i++){
61 for(int j=0;j<k;j++){
62 if(rowToposort[i] == colToposort[j]){
63 matrix[i][j] = colToposort[j];
64 }
65 }
66 }
67 return matrix;
68
69 }
70}

Callers

nothing calls this directly

Calls 1

topoSortMethod · 0.95

Tested by

no test coverage detected