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

Class Solution

FindValidMatrixGivenRowAndColumnSums.java:1–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public int[][] restoreMatrix(int[] rowSum, int[] colSum) {
3 int rows = rowSum.length;
4 int cols = colSum.length;
5 int r=0;
6 int c=0;
7 int resMatrix[][] = new int[rows][cols];
8 while(r<rows && c<cols){
9 int minVal = Math.min(rowSum[r],colSum[c]);
10 resMatrix[r][c] = minVal;
11 rowSum[r]-=minVal;
12 colSum[c]-=minVal;
13 if(rowSum[r]==0){
14 r++;
15 }else{
16 c++;
17 }
18 }
19 return resMatrix;
20 }
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected