1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold Medium

@problem@discussion
#Array#Binary Search#Matrix#Prefix Sum



1/**
2 * [1292] Maximum Side Length of a Square with Sum Less than or Equal to Threshold
3 *
4 * Given a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 if there is no such square.
5 *  
6 * Example 1:
7 * <img alt="" src="https://assets.leetcode.com/uploads/2019/12/05/e1.png" style="width: 335px; height: 186px;" />
8 * Input: mat = [[1,1,3,2,4,3,2],[1,1,3,2,4,3,2],[1,1,3,2,4,3,2]], threshold = 4
9 * Output: 2
10 * Explanation: The maximum side length of square with sum less than 4 is 2 as shown.
11 * 
12 * Example 2:
13 * 
14 * Input: mat = [[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2],[2,2,2,2,2]], threshold = 1
15 * Output: 0
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	m == mat.length
21 * 	n == mat[i].length
22 * 	1 <= m, n <= 300
23 * 	0 <= mat[i][j] <= 10^4
24 * 	0 <= threshold <= 10^5
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/
30// discuss: https://leetcode.com/problems/maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn max_side_length(mat: Vec<Vec<i32>>, threshold: i32) -> i32 {
36        0
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_1292() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.