maxSum
to store the maximum hourglass sum found.i
and j
, skipping the last two rows and columns to avoid index out of bounds.(i, j)
, calculate the sum of the hourglass pattern.maxSum
if the current hourglass sum is greater than the previously recorded maximum.maxSum
as the result.