Swift solution
Complexity\n- Time complexity: O(m * n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n
# Complexity\n- Time complexity: $$O(m * n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    func largestSubmatrix(_ matrix: [[Int]]) -> Int {\n        var result = 0\n\n        var prevHeights = [(col: Int, height: Int)]()\n        for i in 0 ..< matrix.count {\n            var newHeights = [(col: Int, height: Int)]()\n            var visited = Set<Int>()\n            for prev in prevHeights where matrix[i][prev.col] == 1 {\n                visited.insert(prev.col)\n                newHeights.append((prev.col, prev.height + 1))\n            }\n            for j in 0 ..< matrix[0].count where matrix[i][j] == 1 && !visited.contains(j) {\n                newHeights.append((j, 1))\n            }\n\n            for j in 0 ..< newHeights.count {\n                result = max(result, newHeights[j].height * (j + 1))\n            }\n\n            prevHeights = newHeights\n        }\n\n        return result\n    }\n}\n```
['Array', 'Greedy', 'Swift', 'Sorting', 'Matrix']