Range Addition II


hi @vinod23, in
Approach #2
, for clarification, i think it's good to create theminX
andminY
variables, and not to reusem
andn
:)class Solution { func maxCount(_ m: Int, _ n: Int, _ ops: [[Int]]) > Int { var minX = m var minY = n for op in ops { minX = min(op[0], minX) minY = min(op[1], minY) } return minX * minY } }

We can also add this solution as something that was accepted, but not better. As this has the time complexity of x*(m + n).
class Solution { public int maxCount(int m, int n, int[][] ops) { int[] rows = new int[m]; int[] cols = new int[n]; int max = 0; for(int[] op: ops) { for(int i = 0; i < op[0]; ++i) { rows[i]++; if(max < rows[i]) max = rows[i]; } for(int j = 0; j < op[1]; ++j) { cols[j]++; if(max < cols[j]) max = cols[j]; } } int rowCount = 0; int colCount = 0; for(int i = 0; i < m; ++i) { if(rows[i] == max) rowCount++; } for(int i = 0; i < n; ++i) { if(cols[i] == max) colCount++; } return rowCount * colCount; } }