Leetcode 1711 Solution
This article provides solution to leetcode question 1711 (find-valid-matrix-given-row-and-column-sums)
Access this page by simply typing in "lcs 1711" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums
Solution
class Solution:
def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -> List[List[int]]:
m = len(rowSum)
n = len(colSum)
ans = [[0 for _ in range(n)] for _ in range(m)]
for i in range(m):
for j in range(n):
ans[i][j] = max(0, min(rowSum[i], colSum[j]))
rowSum[i] -= ans[i][j]
colSum[j] -= ans[i][j]
return ans