Tap here to switch tabs
Problem
Submissions

Problem: Maximum Sum of an Hourglass

med
30 min
Try to solve the Maximum Sum of an Hourglass problem.

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

med
30 min
Try to solve the Maximum Sum of an Hourglass problem.

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