Sort by

recency

|

420 Discussions

|

  • + 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 
    
  • + 0 comments

    My solutions:

    def _count_cube(A, i, j):
        count=2
        count+=max(A[i][j]- (A[i-1][j] if i>0 else 0), 0)
        count+=max(A[i][j]- (A[i][j-1] if j>0 else 0), 0)
        count+=max(A[i][j]- (A[i+1][j] if i<len(A)-1 else 0), 0)
        count+=max(A[i][j]- (A[i][j+1] if j<len(A[i])-1 else 0), 0)
        
        return count
        
    
    def surfaceArea(A):
        count=0
        for i in range(len(A)):
            for j in range(len(A[0])):
                count+=_count_cube(A, i, j)
        return count  
        # Write your code here
    
  • + 0 comments

    Here is my c++ implementation

    int surfaceArea(vector<vector<int>> A) {
        int result = 0;
        for(int i = 0; i < A.size(); i++){
            for(int j = 0; j < A[0].size(); j++){
                result += 4 * A[i][j] + 2;
                if(i > 0) result -= min(A[i][j], A[i-1][j]) * 2;
                if(j > 0) result -= min(A[i][j], A[i][j-1]) * 2;
            }
        }
        return result;
    }
    
  • + 0 comments

    IS This Wrong ? ** **I calculated first all sides area and then substrating accordingli ?

    int surfaceArea(int A_rows, int A_columns, int** A) {
        
        int area =6*A_rows*A_columns;
        int min = A_rows < A_columns ?  A_rows : A_columns;
         for (int i =0; i<A_rows;i++) {
              for (int j =0; j<A_columns;j++){
                  area -= min - A[i][j];
              }
        
        }
        
        for (int i =0;i<A_columns;i++) {
            area -= min - A[0][i];
        
        }
        
         for (int i =0;i<A_columns;i++) {
            area -= min - A[A_rows-1][i];
        
        }
        
         for (int i =0;i<A_rows;i++) {
            area -= min - A[i][0];
        
        }
        
         for (int i =0;i<A_rows;i++) {
            area -= min - A[i][A_columns-1];
        
        }
        
        for (int i =0; i<A_rows;i++) {
            for (int j=0; j<A_columns;j++) {
                area = area + min - A[0][0] + min - A[A_rows-1][A_columns-1]  + min- A[0][A_columns-1] + min -  A[A_rows-1][0];
            
            }
        
        }
        if(A_columns == 1 &&  A_rows == 1 )
        {
            return area;
        }
        return area-1;
    
    }