Tap here to switch tabs
Problem
Submissions

Problem: Max Increase to Keep City Skyline

med
30 min
Try to solve the Max Increase to Keep City Skyline problem.

Statement

There is an n×nn \times n city represented by an integer matrix grid, where grid[r][c] denotes the height of the building located at row r and column c.

The skyline of the city is the outer contour formed by all buildings when viewed from the four cardinal directions:

  • The skyline viewed from the north or south is the maximum value in each column.

  • The skyline viewed from the east or west is the maximum value in each row.

You are allowed to increase the height of any number of buildings by any non negative amount, provided that the city skyline viewed from all four directions remains unchanged.

Return the maximum total sum by which the building heights can be increased.

Constraints:

  • n ==== grid.length

  • n ==== grid[r].length

  • 2≤2 \leq n ≤50\leq 50

  • 0≤0 \leq grid[r][c] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Max Increase to Keep City Skyline

med
30 min
Try to solve the Max Increase to Keep City Skyline problem.

Statement

There is an n×nn \times n city represented by an integer matrix grid, where grid[r][c] denotes the height of the building located at row r and column c.

The skyline of the city is the outer contour formed by all buildings when viewed from the four cardinal directions:

  • The skyline viewed from the north or south is the maximum value in each column.

  • The skyline viewed from the east or west is the maximum value in each row.

You are allowed to increase the height of any number of buildings by any non negative amount, provided that the city skyline viewed from all four directions remains unchanged.

Return the maximum total sum by which the building heights can be increased.

Constraints:

  • n ==== grid.length

  • n ==== grid[r].length

  • 2≤2 \leq n ≤50\leq 50

  • 0≤0 \leq grid[r][c] ≤100\leq 100