-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetting_Started.cpp
68 lines (54 loc) · 1.23 KB
/
Getting_Started.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int findMaxSquareWithAllZeros(int **arr, int n, int m)
{
if(n==0 && m==0){
return 0;
}
pair<int,int> p ;
p.first=
//Write your code here
int storage[n][m];
int max_val = INT_MIN;
for(int i=0;i<n;i++) {
storage[i][0] = arr[i][0] == 0 ? 1: 0;
max_val = max(storage[i][0], max_val);
}
for(int i=0;i<m;i++) {
storage[0][i] = arr[0][i] ==0 ? 1: 0;
max_val = max(storage[0][i], max_val);
}
for(int i=1;i<n;i++) {
for(int j=1;j<m;j++ ) {
if(arr[i][j]==1){
storage[i][j] = 0;
}
else{
storage[i][j] = min(min(storage[i-1][j-1], storage[i-1][j] ), storage[i][j-1]) + 1 ;
}
max_val = max(storage[i][j], max_val);
}
}
return max_val;
}
int main()
{
int **arr, n, m, i, j;
cin >> n >> m;
arr = new int *[n];
for (i = 0; i < n; i++)
{
arr[i] = new int[m];
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> arr[i][j];
}
}
cout << findMaxSquareWithAllZeros(arr, n, m) << endl;
delete[] arr;
return 0;
}