#598
Easy Algorithms Range addition ii
Array Math
58.4% acceptance
Jan 13, 2026
1033
986
You are given an m x n matrix M initialized with all 0's and an array of operations ops, where ops[i] = [ai, bi] means M[x][y] should be incremented by one for all 0 <= x < ai and 0 <= y < bi.
Count and return the number of maximum integers in the matrix after performing all the operations.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn max_count(m: i32, n: i32, ops: Vec<Vec<i32>>) -> i32 {
let min_r = ops.iter().map(|o| o[0]).min().unwrap_or(m);
let min_c = ops.iter().map(|o| o[1]).min().unwrap_or(n);
min_r * min_c
}
}