Problem statement

https://binarysearch.com/problems/Condo-Developers/

Solution

Variation of Leetcode 0807 Max Increase to Keep City Skyline.

Complexity

It is O(mn) for time and space.

Code

class Solution:
    def solve(self, grid):
        n, m, ans = len(grid), len(grid[0]), 0
        V = [max(i) for i in zip(*grid)]
        H = [max(i) for i in grid]
        for i, j in product(range(m), range(n)):
            grid[j][i] = min(V[i], H[j])        
        return grid