Explained  || reverse iteration - O(N) || Very simple and easy to understand solution
 Up vote if you like the solution \n## Approach \n1. Here iterate from the end & Keep track number of rows and number of cols that can be assigned a value\n3. A
<b> Up vote if you like the solution </b>\n## Approach \n1. Here iterate from the end & Keep track number of rows and number of cols that can be assigned a value\n3. Add to answer val * remaining row when col operation is performed &\n    add to answer val * remaining col when row operation is performed.\n4. Decreament remaining row when row operation is performed &\n    reamining col when col operation is performed\n\nNote : The trick is to when ever we perform a row operation then number of column remaining for next col operation 1 less and same is the case for col operation.\n\nFAQ : Why we are considering only once every index, even there is duplicate possible ?\nAns: Even if there is duplicate, the last one will overwrite the effect of the previous query excution on the same index. So as we iterate from last, we need to only consider the last one and not any other occurance of it.\n\n## Complexity \nTime : O(N) where N = q.size()\nSpace : O(N) where N = n\n\n## Code\n\n```\nlong long matrixSumQueries(int n, vector<vector<int>>& q) {\n    vector<bool> rowFlag(n, 1), colFlag(n, 1);\n    long long ans = 0, rowRemain = n, colRemain = n;\n    for(int i = q.size()-1; i >= 0; --i){\n        if(q[i][0] == 0 && rowFlag[q[i][1]]) { ans += colRemain * q[i][2];    rowFlag[q[i][1]] = 0; rowRemain--; }\n        if(q[i][0] == 1 && colFlag[q[i][1]]) { ans += rowRemain * q[i][2];    colFlag[q[i][1]] = 0; colRemain--; }\n    }\n    return ans;\n}\n\n```\n\n<b>Here is an article of my recent interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:\nhttps://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted\n
['C++']