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.
my approch has -1 calculation on each glass and no additional array sum. Look on it.
.
'''
def hourglassSum(arr):
len_arr = len(arr)
n=(len_arr-2)**2
s_max = None
for k in range(n):
i = k//(len_arr-2)
j = k%(len_arr-2)
if j==0: # new row glass sum
_ = sum((arr[i][0],arr[i][1],arr[i][2],
arr[i+1][1],
arr[i+2][0],arr[i+2][1],arr[i+2][2])
if(s_max is None):
s_max = _
else: # next glass in the same row sum calc
_ += (-arr[i][j-1]-arr[i+1][j]-arr[i+2][j-1] + \
arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j+2])
s_max = max(s_max,_)
return s_max
'''
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 →
my approch has -1 calculation on each glass and no additional array sum. Look on it. . '''