C++ | Priority Queue | Cleanest Code
\nclass Solution {\npublic:\n    int kthLargestValue(vector<vector<int>>& matrix, int k) {\n        //its just like 2d prefix sums\n        int n=matrix.size();
```\nclass Solution {\npublic:\n    int kthLargestValue(vector<vector<int>>& matrix, int k) {\n        //its just like 2d prefix sums\n        int n=matrix.size();\n        int m=matrix[0].size();\n        vector<vector<int>> prefix(n,vector<int>(m));\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(i==0 and j==0){\n                    prefix[i][j]=matrix[i][j];\n                }\n                else if(i==0 and j!=0){\n                    prefix[i][j]=prefix[i][j-1]^matrix[i][j];\n                }\n                else if(i!=0 and j==0){\n                    prefix[i][j]=prefix[i-1][j]^matrix[i][j];\n                }\n                else{\n                    prefix[i][j]=prefix[i-1][j]^prefix[i][j-1]^prefix[i-1][j-1]^matrix[i][j];\n                }\n            }\n        }\n        priority_queue<int,vector<int>,greater<int>> pq;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                pq.push(prefix[i][j]);\n                if(pq.size()>k){\n                    pq.pop();\n                }\n            }\n        }\n        return pq.top();\n    }\n};\n```
[]