bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 807. Max Increase to Keep City Skyline

807. Max Increase to Keep City Skyline

Leetcode Solutions

Max Increase to Keep City Skyline

  1. Initialize two arrays, row_maxes and col_maxes, to store the maximum heights of each row and column respectively.
  2. Iterate through each cell in the grid, updating the maximum heights in row_maxes and col_maxes.
  3. Initialize a variable total_increase to store the total sum of increases.
  4. Iterate through each cell in the grid again, this time calculating the minimum of the corresponding values in row_maxes and col_maxes.
  5. Increase the building height to this minimum value if it is greater than the current height.
  6. Add the difference between the new height and the original height to total_increase.
  7. Return total_increase as the final result.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...