C++ | prefix xor | priority queue
\n\nclass Solution {\npublic:\n    int kthLargestValue(vector<vector<int>>& mt, int k) {\n        //min priority queue for storing k largest element\n        pr
\n```\nclass Solution {\npublic:\n    int kthLargestValue(vector<vector<int>>& mt, int k) {\n        //min priority queue for storing k largest element\n        priority_queue<int,vector<int >,greater<int> >pq;\n        \n        int m = mt.size(),n = mt[0].size();\n        \n        //mt[i][j] = xor of all elements mt[i][j] where 0 <= i <= a < m and 0 <= j <= b < n \n        /*\n        \n          else part is most tricky part\n          mt[i][j] ^= (mt[i][j-1] ^ mt[i-1][j] ^ mt[i-1][j-1]);\n          since upto mt[i][j] where i>=1&&j>=1,elements upto mt[i-1][j-1] are getting counted twice \n          that\'s why we are taking xor of them again\n          because a^b^b = a;\n         */\n        for(int i = 0 ; i < m ; i++) {\n            for(int j = 0 ; j < n ; j++) {\n                if(i == 0 && j == 0); //do nothing\n                else if(i == 0)\n                    mt[i][j] ^= mt[i][j-1];\n                else if\n                    (j == 0) mt[i][j] ^= mt[i-1][j];\n                else\n                    mt[i][j] ^= (mt[i][j-1] ^ mt[i-1][j] ^ mt[i-1][j-1]);\n                \n                pq.push(mt[i][j]);\n                \n                if(pq.size() > k) pq.pop();\n            }\n        }\n        return pq.top();\n    }\n};\n```
[]