Sort by

recency

|

422 Discussions

|

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