Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of an Hourglass

Maximum Sum of an Hourglass asks you to find the largest total among all fully contained patterns with three cells on top, one centered cell, and three cells below in an integer matrix.

Statement

You are given an m × \times n integer matrix grid.

An hourglass is defined as a subset of elements from grid forming the following structure:
grid[r][c], grid[r][c + 1], grid[r][c + 2]
grid[r + 1][c + 1]
grid[r + 2][c], grid[r + 2][c + 1], grid[r + 2][c + 2]

Return the maximum sum of elements among all valid hourglasses in grid.

Note: An hourglass cannot be rotated and must be fully contained within the grid boundaries.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 3≤3 \leq m, n ≤150\leq 150

  • 0≤0 \leq grid[i][j] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of an Hourglass

Maximum Sum of an Hourglass asks you to find the largest total among all fully contained patterns with three cells on top, one centered cell, and three cells below in an integer matrix.

Statement

You are given an m × \times n integer matrix grid.

An hourglass is defined as a subset of elements from grid forming the following structure:
grid[r][c], grid[r][c + 1], grid[r][c + 2]
grid[r + 1][c + 1]
grid[r + 2][c], grid[r + 2][c + 1], grid[r + 2][c + 2]

Return the maximum sum of elements among all valid hourglasses in grid.

Note: An hourglass cannot be rotated and must be fully contained within the grid boundaries.

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 3≤3 \leq m, n ≤150\leq 150

  • 0≤0 \leq grid[i][j] ≤106\leq 10^6