Maximum subgrid sum

Write codeMedium16 min

Your task

A hospital floor is mapped as a grid where each cell holds the number of patient interactions logged in that zone this week. Facilities wants to place a supply station covering an h-by-w block of zones (h rows by w columns, axis-aligned) where the block's total interactions are highest. Given the non-empty grid and integers h and w (guaranteed to fit inside the grid), return the maximum block total. Cell values may be negative for closed zones. Example: grid = [[1, 2, 3], [4, 5, 6]], h = 1, w = 2 gives 11.

Examples

busiest_block(grid: list[list[int]], h: int, w: int) -> int
Example 1
Inputbusiest_block([[1, 2, 3], [4, 5, 6]], 1, 2)
Output11