Class Solution
java.lang.Object
g0301_0400.s0363_max_sum_of_rectangle_no_larger_than_k.Solution
363 - Max Sum of Rectangle No Larger Than K.<p>Hard</p>
<p>Given an <code>m x n</code> matrix <code>matrix</code> and an integer <code>k</code>, return <em>the max sum of a rectangle in the matrix such that its sum is no larger than</em> <code>k</code>.</p>
<p>It is <strong>guaranteed</strong> that there will be a rectangle with a sum no larger than <code>k</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/03/18/sum-grid.jpg" alt="" /></p>
<p><strong>Input:</strong> matrix = [[1,0,1],[0,-2,3]], k = 2</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> Because the sum of the blue rectangle [[0, 1], [-2, 3]] is 2, and 2 is the max number no larger than k (k = 2).</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> matrix = [[2,2,-1]], k = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == matrix.length</code></li>
<li><code>n == matrix[i].length</code></li>
<li><code>1 <= m, n <= 100</code></li>
<li><code>-100 <= matrix[i][j] <= 100</code></li>
<li><code>-10<sup>5</sup> <= k <= 10<sup>5</sup></code></li>
</ul>
<p><strong>Follow up:</strong> What if the number of rows is much larger than the number of columns?</p>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxSumSubmatrix
public int maxSumSubmatrix(int[][] matrix, int k)
-