-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaximumRectangularSubmatrixOf1s.java
35 lines (33 loc) · 1.11 KB
/
MaximumRectangularSubmatrixOf1s.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class MaximumRectangularSubmatrixOf1s {
public int maximum(int input[][]){
int temp[] = new int[input[0].length];
MaximumHistogram mh = new MaximumHistogram();
int maxArea = 0;
int area = 0;
for(int i=0; i < input.length; i++){
for(int j=0; j < temp.length; j++){
if(input[i][j] == 0){
temp[j] = 0;
}else{
temp[j] += input[i][j];
}
}
area = mh.maxHistogram(temp);
if(area > maxArea){
maxArea = area;
}
}
return maxArea;
}
public static void main(String args[]){
int input[][] = {{1,1,1,0},
{1,1,1,1},
{0,1,1,0},
{0,1,1,1},
{1,0,0,1},
{1,1,1,1}};
MaximumRectangularSubmatrixOf1s mrs = new MaximumRectangularSubmatrixOf1s();
int maxRectangle = mrs.maximum(input);
System.out.println("Max rectangle is of size " + maxRectangle);
}
}