Reverse Iteration through queries || Python
Explanation\n- Do reverse iteration through queries because latest rows and cols have contribution to our final answer.\n- Add visited rows and cols to hash set
# Explanation\n- Do reverse iteration through queries because latest rows and cols have contribution to our final answer.\n- Add visited rows and cols to hash set.\n# Complexity\n`Time O(length of queries)`\n`Space O(N)`\n# Code\n```\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        cols, rows = set(), set()\n        res = 0\n        for ty, index, val in queries[::-1]:\n            if ty:\n                if index not in cols:\n                    cols.add(index)\n                    res += val * n\n                    res -= val * len(rows)\n            else:\n                if index not in rows:\n                    rows.add(index)\n                    res += val * n\n                    res -= val * len(cols)\n        return res\n```\nUpVote, if you like **:)**
['Hash Table']