Track Visited Rows & Columns using set | O(n) | Python | Swift
Complexity\n- Time complexity: O(n) n is number of queries\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(m) m is the size of the matix\n 
# Complexity\n- Time complexity: **O(n)** n is number of queries\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(m)** m is the size of the matix\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python []\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        visitedCols = set()\n        visitedRows = set()\n        res = 0\n        for query in reversed(queries):\n            if query[0] == 0:\n                if query[1] not in visitedRows:\n                    visitedRows.add(query[1])\n                    res += (n - len(visitedCols)) * query[2]\n            else:\n                if query[1] not in visitedCols:\n                    visitedCols.add(query[1])\n                    res += (n - len(visitedRows)) * query[2]\n        return res\n```\n```swift []\nclass Solution {\n    func matrixSumQueries(_ n: Int, _ queries: [[Int]]) -> Int {\n        var visitedCols: Set<Int> = []\n        var visitedRows: Set<Int> = []\n        var res = 0\n        for query in queries.reversed() {\n            if query[0] == 0 {\n                if visitedRows.insert(query[1]).inserted {\n                    res += (n - visitedCols.count) * query[2]\n                }\n            } else if visitedCols.insert(query[1]).inserted {\n                res += (n - visitedRows.count) * query[2]\n            }\n        }\n        return res\n    }\n}\n```
['Swift', 'Matrix', 'Python3']