#2718
Sum of Matrix After Queries
expert · 1095 · lc medium +32 · verified · 31.9% accepted · 732 likes · top 9%
Description
Start with an n x n all-zero matrix. Each query [typei, indexi, vali] sets all values in row indexi (when typei == 0) or column indexi (when typei == 1) to vali, overwriting prior values. After all queries, return the matrix sum.
Example 1:
Input: n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]]
Output: 23
Explanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 23.
Example 2:
Input: n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]
Output: 17
Explanation: The image above describes the matrix after each query. The sum of the matrix after all queries are applied is 17.
Code
1
2
3