Ruby || O(m*n*log(n))/O(1)
\n# Complexity\n- Time complexity:\nO(mnlog(n))\n\n- Space complexity:\nO(1)\n\n# Code\nruby\nclass Numeric\n    def max(v) = (self < v ? v : self)\nend\n\ndef 
\n# Complexity\n- Time complexity:\n$$O(m*n*log(n))$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```ruby\nclass Numeric\n    def max(v) = (self < v ? v : self)\nend\n\ndef largest_submatrix(matrix)\n    h, w = matrix.size, matrix.first.size\n    matrix.each_cons(2).inject(matrix.first.filter(&:positive?).size) {|res, (row1, row2)|\n        row1.each_with_index {|v, cidx| row2[cidx] += v if row2[cidx].positive? }\n        row2.sort.each_with_index.inject(res) {|res1, (v, i)| res1.max(v * (w - i))}\n    }\nend\n\n```
['Ruby']