Tap here to switch tabs
Problem
Submissions

Problem: Find Valid Matrix Given Row and Column Sums

Try to solve the Find Valid Matrix Given Row and Column Sums problem.

Statement

You are given two arrays of nonnegative integers rowSum and colSum, where rowSum[i] represents the required sum of the elements in the ithi^{\text{th}} row and colSum[j] represents the required sum of the elements in the jthj^{\text{th}} column of a 2D2\text{D} matrix.

Construct and return a 2D2\text{D} matrix of dimensions rowSum.length ×\times colSum.length consisting of nonnegative integers that satisfies the given row and column sums.

Note: If multiple valid matrices exist, you may return any of them.

Constraints:

  • 1≤1 \leq rowSum.length, colSum.length ≤500\leq 500

  • 0≤0 \leq rowSum[i], colSum[i] ≤108\leq 10^8

  • sum(rowSum) ==== sum(colSum)

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Valid Matrix Given Row and Column Sums

Try to solve the Find Valid Matrix Given Row and Column Sums problem.

Statement

You are given two arrays of nonnegative integers rowSum and colSum, where rowSum[i] represents the required sum of the elements in the ithi^{\text{th}} row and colSum[j] represents the required sum of the elements in the jthj^{\text{th}} column of a 2D2\text{D} matrix.

Construct and return a 2D2\text{D} matrix of dimensions rowSum.length ×\times colSum.length consisting of nonnegative integers that satisfies the given row and column sums.

Note: If multiple valid matrices exist, you may return any of them.

Constraints:

  • 1≤1 \leq rowSum.length, colSum.length ≤500\leq 500

  • 0≤0 \leq rowSum[i], colSum[i] ≤108\leq 10^8

  • sum(rowSum) ==== sum(colSum)