-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest3.py
61 lines (44 loc) · 1.34 KB
/
test3.py
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
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'largestMatrix' function below.
#
# The function is expected to return an INTEGER.
# The function accepts 2D_INTEGER_ARRAY arr as parameter.
#
def largestMatrix(arr):
# Write your code here
R = len(arr) # no. of rows in M[][]
C = len(arr[0]) # no. of columns in M[][]
S = [[0 for k in range(C+1)] for l in range(R+1)]
# here we have set the first row and column of S[][]
# Construct other entries
for i in range(1, R+1):
for j in range(1, C+1):
if (arr[i-1][j-1] == 1):
S[i][j] = min(S[i][j-1], S[i-1][j],
S[i-1][j-1]) + 1
else:
S[i][j] = 0
# Find the maximum entry and
# indices of maximum entry in S[][]
max_of_s = S[0][0]
for i in range(R+1):
for j in range(C+1):
if (max_of_s < S[i][j]):
max_of_s = S[i][j]
return max_of_s
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
arr_rows = int(input().strip())
arr_columns = int(input().strip())
arr = []
for _ in range(arr_rows):
arr.append(list(map(int, input().rstrip().split())))
result = largestMatrix(arr)
fptr.write(str(result) + '\n')
fptr.close()