illustrated explanation
<-- please vote\n\n\n\n    def maximalRectangle(self, matrix: List[List[str]]) -> int:\n        """ O(NM)TS """\n        ans = []\n        prefix = [zip(([itert
<-- please vote\n\n![image](https://assets.leetcode.com/users/images/0f9c1431-a088-4d22-b810-5abfd51f4630_1648848619.0584486.png)\n\n    def maximalRectangle(self, matrix: List[List[str]]) -> int:\n        """ O(NM)TS """\n        ans = []\n        prefix = [*zip(*([*itertools.accumulate(map(int, col), lambda x, y: x + y if y == 1 else 0)] for col in zip(*matrix)))]\n\n        for row in prefix:\n            stack = [-1]\n            for i, n in enumerate(row):\n                while len(stack) > 1 and row[stack[-1]] >= n:\n                    ans += row[stack.pop()] * (i - stack[-1] - 1),\n                stack += i,\n            while len(stack) > 1:\n                ans += row[stack.pop()] * (len(row) - stack[-1] - 1),\n\n        return max(ans)\n\t\t\n\nsee the problem 84\n\n![image](https://assets.leetcode.com/users/images/25726517-a8f6-4496-9756-8ee5d78a0a1d_1648848646.6423938.png)\n\nhow to use pref summ\n\n\n![image](https://assets.leetcode.com/users/images/afee3df3-6d24-4b1b-9a54-b5bce4bb1679_1648848659.2007706.png)\n\n![image](https://assets.leetcode.com/users/images/28fa08c0-f430-4f32-98ff-c016d18e16e4_1648848666.474494.png)\n
['Python']