1D dp + heap | 2 optimizes by memory
Complexity\n- Time complexity: O(m \cdot n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(\min(n, k))\n Add your space complexity here, e
# Complexity\n- Time complexity: $$O(m \\cdot n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(\\min(n, k))$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nimport heapq\n\nclass Solution:\n    def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:\n        h = []\n        def add_value(value):\n            if len(h) == k:\n                if value > h[0]:\n                    heapq.heapreplace(h, value)\n            else:\n                heapq.heappush(h, value)\n        \n        dp_prev_line = [0] * (len(matrix[0]) + 1)\n        for line in matrix:\n            dp_line = [0]\n            for j, elem in enumerate(line, 1):\n                current = (\n                    elem\n                    ^ dp_prev_line[j]\n                    ^ dp_line[j - 1]\n                    ^ dp_prev_line[j - 1]\n                )\n                dp_line.append(current)\n                add_value(current)\n            dp_prev_line = dp_line\n        \n        return h[0]\n```
['Dynamic Programming', 'Heap (Priority Queue)', 'Matrix', 'Python3']