92 Views

print the largest maximum hourglass sum found in array,in c program


Nikhil sharma 1st Jun, 2021
Answer (1)
Palak kumari 1st Jun, 2021

Hey there,

def array2D(arr):


# want to find the maximum hourglass sum

# minimum hourglass sum = -9 * 7 = -63

maxSum = -63

for i in range(4):

for j in range(4):

# sum of top 3 elements

top = sum(arr[i][j:j+3])

# sum of the mid element

mid = arr[i+1][j+1]

# sum of bottom 3 elements

bottom = sum(arr[i+2][j:j+3])

hourglass = top + mid + bottom

if hourglass > maxSum:

maxSum = hourglass

return maxSum

Hope it helps!

Related Questions

Amity University-Noida B.Tech...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
Amity University-Noida M.Tech...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
Amity University-Noida BBA Ad...
Apply
Among top 100 Universities Globally in the Times Higher Education (THE) Interdisciplinary Science Rankings 2026
VIT Bhopal University | B.Arc...
Apply
Mark presence in the Modern Architectural field with Bachelor of Architecture | Highest CTC : 70 LPA | Accepts NATA Score
New Horizon College BBA Admis...
Apply
UG Admissions 2026 open| NAAC ‘A’ grade | Merit-based Scholarships available.
VIT Bhopal University | Integ...
Apply
Integrated M.Tech admissions open @ VIT Bhopal University | Highest CTC 70 LPA | Application Closing Soon | Apply now
View All Application Forms

Download the Careers360 App on your Android phone

Regular exam updates, QnA, Predictors, College Applications & E-books now on your Mobile

150M+ Students
30,000+ Colleges
500+ Exams
1500+ E-books