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

Leetcode Problem 892. Surface Area of 3D Shapes

892. Surface Area of 3D Shapes

Leetcode Solutions

Calculating Surface Area by Subtracting Hidden Faces

  1. Initialize a variable total_area to 0 to store the total surface area.
  2. Iterate over each cell (i, j) in the grid.
    • If grid[i][j] is greater than 0, add grid[i][j] * 4 + 2 to total_area (4 sides and top and bottom faces).
    • If there is a cell to the left (i, j-1), subtract min(grid[i][j], grid[i][j-1]) * 2 from total_area.
    • If there is a cell above (i-1, j), subtract min(grid[i][j], grid[i-1][j]) * 2 from total_area.
  3. Return total_area as the result.
UML Thumbnail

Brute Force Calculation of Surface Area

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...