Cells with Odd Values in a Matrix LeetCode solution in C++
1static int x = []() {2std::ios::sync_with_stdio(false);3cin.tie(nullptr);4return 0;5}();67class Solution { // tc: O(n+m) & sc: O(n+m)8public:9int oddCells(int n, int m, vector<vector<int>> &indices) {10vector<bool> rows(n, false), cols(m, false);11for (auto index : indices) {12rows[index[0]] = rows[index[0]] ^ true;13cols[index[1]] = cols[index[1]] ^ true;14}1516int r(0), c(0);17for (int i(0); i < n; i++) {18if (rows[i]) r++;19}2021for (int i(0); i < m; i++) {22if (cols[i]) c++;23}24return r * (m - c) + c * (n - r); // (or) return (r*m + c*n - 2*r*c);25}26};