-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy path01 - 2D Arrays - DS.py
42 lines (34 loc) · 1.04 KB
/
01 - 2D Arrays - DS.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
# ========================
# Information
# ========================
# Direct Link: https://www.hackerrank.com/challenges/2d-array/problem
# Difficulty: Easy
# Max Score: 15
# Language: Python
# ========================
# Solution
# ========================
import os
# Complete the hourglassSum function below.
def hourglassSum(arr):
new_array = []
for i in range(len(arr)):
for j in range(len(arr[i])):
new_array.append(arr[i][j:j+3])
second_array = []
for i in range(len(new_array)-13):
if len(new_array[i]) == 3:
temp = []
temp.extend(new_array[i])
temp.extend(new_array[i+12])
temp.extend(new_array[i+6][1:2])
second_array.append(sum(temp))
return max(second_array)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
ARRAY = []
for _ in range(6):
ARRAY.append(list(map(int, input().rstrip().split())))
RESULT = hourglassSum(ARRAY)
fptr.write(str(RESULT) + '\n')
fptr.close()