|
| 1 | +<p>You are given a <strong>0-indexed</strong> integer matrix <code>grid</code> and an integer <code>k</code>.</p> |
| 2 | + |
| 3 | +<p>Return <em>the <strong>number</strong> of <span data-keyword="submatrix">submatrices</span> that contain the top-left element of the</em> <code>grid</code>, <em>and have a sum less than or equal to </em><code>k</code>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | +<img alt="" src="https://assets.leetcode.com/uploads/2024/01/01/example1.png" style="padding: 10px; background: #fff; border-radius: .5rem;" /> |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> grid = [[7,6,3],[6,6,1]], k = 18 |
| 10 | +<strong>Output:</strong> 4 |
| 11 | +<strong>Explanation:</strong> There are only 4 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 18.</pre> |
| 12 | + |
| 13 | +<p><strong class="example">Example 2:</strong></p> |
| 14 | +<img alt="" src="https://assets.leetcode.com/uploads/2024/01/01/example21.png" style="padding: 10px; background: #fff; border-radius: .5rem;" /> |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> grid = [[7,2,9],[1,5,0],[2,6,6]], k = 20 |
| 17 | +<strong>Output:</strong> 6 |
| 18 | +<strong>Explanation:</strong> There are only 6 submatrices, shown in the image above, that contain the top-left element of grid, and have a sum less than or equal to 20. |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p> </p> |
| 22 | +<p><strong>Constraints:</strong></p> |
| 23 | + |
| 24 | +<ul> |
| 25 | + <li><code>m == grid.length </code></li> |
| 26 | + <li><code>n == grid[i].length</code></li> |
| 27 | + <li><code>1 <= n, m <= 1000 </code></li> |
| 28 | + <li><code>0 <= grid[i][j] <= 1000</code></li> |
| 29 | + <li><code>1 <= k <= 10<sup>9</sup></code></li> |
| 30 | +</ul> |
0 commit comments