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.
def hourglassSum(arr):
addn=[]
for i in range(6):
for j in range(6):
top=arr[i][j]+arr[i][(j+1)%6]+arr[i][(j+2)%6]
middle=arr[(i+1)%6][(j+1)%6]
bottom=arr[(i+2)%6][j]+arr[(i+2)%6][(j+1)%6]+arr[(i+2)%6][(j+2)%6]
add=top+bottom+middle
addn.append(add)
return max(addn)
This is my attempt. but it doesnt pass all testcases for some reason. can anyone explain?
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 →
def hourglassSum(arr): addn=[] for i in range(6): for j in range(6): top=arr[i][j]+arr[i][(j+1)%6]+arr[i][(j+2)%6] middle=arr[(i+1)%6][(j+1)%6] bottom=arr[(i+2)%6][j]+arr[(i+2)%6][(j+1)%6]+arr[(i+2)%6][(j+2)%6] add=top+bottom+middle addn.append(add)
This is my attempt. but it doesnt pass all testcases for some reason. can anyone explain?