Leetcode 919 Solution

This article provides solution to leetcode question 919 (projection-area-of-3d-shapes)

https://leetcode.com/problems/projection-area-of-3d-shapes

Solution

class Solution:
    def projectionArea(self, grid: List[List[int]]) -> int:
        n = len(grid)

        im = collections.defaultdict(int)
        jm = collections.defaultdict(int)

        ans = 0
        for i, j in itertools.product(range(n), range(n)):
            if grid[i][j] == 0:
                continue

            im[i] = max(im[i], grid[i][j])
            jm[j] = max(jm[j], grid[i][j])
            ans += 1

        return ans + sum(im.values()) + sum(jm.values())