Tap here to switch tabs
Problem
Submissions

Problem: Find Valid Matrix Given Row and Column Sums

med
30 min
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 iextthi^{ ext{th}} row and colSum[j] represents the required sum of the elements in the jextthj^{ ext{th}} column of a 2extD2 ext{D} matrix.

Construct and return a 2extD2 ext{D} matrix of dimensions rowSum.length $ imes$ 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

med
30 min
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 iextthi^{ ext{th}} row and colSum[j] represents the required sum of the elements in the jextthj^{ ext{th}} column of a 2extD2 ext{D} matrix.

Construct and return a 2extD2 ext{D} matrix of dimensions rowSum.length $ imes$ 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)