We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
There seems to be an error in the hidden test case 3 and 6. Manually checked my code's answer, and it is correct.
!/bin/python3
import math
import os
import random
import re
import sys
#
Complete the 'hourglassSum' function below.
#
The function is expected to return an INTEGER.
The function accepts 2D_INTEGER_ARRAY arr as parameter.
#
def hourglassSum(arr):
# Write your code here
maxSum = 0
for i in range(1,5):
for j in range(1,5):
maxSum = max(maxSum, (arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1] + arr[i][j] + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1]))
print(arr)
return maxSum
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
arr = []
for _ in range(6):
arr.append(list(map(int, input().rstrip().split())))
result = hourglassSum(arr)
fptr.write(str(result) + '\n')
fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
There seems to be an error in the hidden test case 3 and 6. Manually checked my code's answer, and it is correct.
!/bin/python3
import math import os import random import re import sys
#
Complete the 'hourglassSum' function below.
#
The function is expected to return an INTEGER.
The function accepts 2D_INTEGER_ARRAY arr as parameter.
#
def hourglassSum(arr): # Write your code here maxSum = 0 for i in range(1,5): for j in range(1,5): maxSum = max(maxSum, (arr[i-1][j-1] + arr[i-1][j] + arr[i-1][j+1] + arr[i][j] + arr[i+1][j-1] + arr[i+1][j] + arr[i+1][j+1]))
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')