Sort by

recency

|

423 Discussions

|

  • + 0 comments

    So here is my code.For an help for you guys just look at the object from front back right left top bottom and you will notice that each of those pairs are equal.Also see the list A and try to get the pattern.Then the coding is simple

    #!/bin/python3
    
    import math
    import os
    import os
    
    def surfaceArea(A):
        D = []
        for a in A:
            S = []
            for i in range(1, W):
                S.append(abs(a[i] - a[i - 1])) 
            D.append(sum(S) + a[-1] + a[0])
    
        E = []
        for d in range(H - 1): 
            for c in range(W):  
                E.append(abs(A[d][c] - A[d + 1][c]))
    
        E.append(sum(A[0]) + sum(A[-1]))  
        return sum(D) + sum(E) + 2 * H * W 
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        first_multiple_input = input().rstrip().split()
    
        H = int(first_multiple_input[0])
        W = int(first_multiple_input[1])
    
        A = []
        for _ in range(H):
            A.append(list(map(int, input().rstrip().split())))
    
        result = surfaceArea(A)
    
        fptr.write(str(result) + '\n')
        fptr.close()
    
        print(A) 
    
  • + 0 comments
    int sum = 0;
        sum += 2 * A.size() * A[0].size(); // it will check count all the top bottom of the stack
        
        for(int i = 0; i< A.size(); i++){
            for(int j = 0; j< A[0].size(); j++){
                
                //it checks, is there any board on north direction or not
                if(i == 0){
                     sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i-1][j]);
                }
                
                // it checks, is there any board on south direction or not
                if(i == A.size()-1){
                     sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i+1][j]);
                }
                
                //it checks, is there any board on west direction or not
                if(j == 0){
                    sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i][j-1]);
                }
                
                //it checks, is there any board on east direction or not
                if(j == A[0].size()-1){
                    sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i][j+1]);
                }
            }
        }
        
        return sum;
    
  • + 0 comments

    JS:

    function surfaceArea(A) {
      if (A.length === 1 && A[0] === 1) return 6;
    
      let surface = 0;
    
      for (let row = 0; row < A.length; row++) {
        const currentRow = A[row];
        for (let col = 0; col < currentRow.length; col++) {
          const height = currentRow[col];
    
          // Add top and bottom surfaces
          surface += 2;
    
          // Add side surfaces
          const neighbors = [
            row > 0 ? A[row - 1][col] : 0, // Front
            row < A.length - 1 ? A[row + 1][col] : 0, // Back
            col > 0 ? currentRow[col - 1] : 0, // Left
            col < currentRow.length - 1 ? currentRow[col + 1] : 0, // Right
          ];
    
          for (const neighbor of neighbors) {
            surface += Math.max(0, height - neighbor);
          }
        }
      }
    
      return surface;
    }
    
  • + 0 comments

    can't understand this question

  • + 0 comments
    def surfaceArea(H,W,A):
        #top & bottom view sides
        top_bot=2*H*W
        ans=0
    		
        #row wise
        for row in A:
            ans+=row[0]+row[W-1] #right and left side of that row
            for i in range(W-1):
                ans+=abs(row[i]-row[i+1])
    						
        #col wise
        ans+=sum(A[0])+sum(A[H-1]) #top row side and bottom row side
        for i in range(H-1):
            for j in range(W):
                ans+=abs(A[i][j]-A[i+1][j])
                
        return ans + top_bot