Sort by

recency

|

1918 Discussions

|

  • + 0 comments

    python

    if __name__ == '__main__':
    
        arr = []
    
        for _ in range(6):
            arr.append(list(map(int, input().rstrip().split())))
            
        row= len(arr)
        p=row-2
        n=[]
        
        while len(n)<=(p*p):
            for i in range(p):
                for j in range(p):
                    
                    summ=(arr[i][j]+arr[i][j+1]+arr[i][j+2])+(arr[i+1][j+1])+(arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2])
                    
                    n.append(summ)
        
        print(max(n))
    
  • + 0 comments

    int[][] a = arr.stream() .map(l -> l.stream().mapToInt(Integer::intValue).toArray()) .toArray(int[][]::new); int r=6,c=6; if(r<3 || c<3){ System.out.println("Not possible"); System.exit(0); } int max_sum=Integer.MIN_VALUE; for(int i=0;i

                for(int j=0;j<c-2;j++){
                    int sum=(a[i][j]+a[i][j+1]+a[i][j+2])+(a[i+1][j+1])+(a[i+2][j]+a[i+2][j+1]+a[i+2][j+2]);
                    max_sum=Math.max(max_sum, sum);
                }
    
            }
            System.out.println(max_sum);
    
  • + 0 comments

    C++ code

    int maxHourGlassSum(vector<vector<int>> arr)
    {
        int sum;
        int max = -100;
        for(int i=0; i<arr.size()-2; i++)
        {
            for(int j=0; j<arr[0].size()-2; j++)
            {
                sum = 0;
                for(int k=0; k<3; k++)
                {
                    sum += arr[i][j+k]+arr[i+2][j+k];
                }
                sum = sum + arr[i+1][j+1];
                if(sum>max)
                    max = sum;
            }
        }
        return max;
    }
    
  • + 1 comment

    Python code:

    arr = []
    for _ in range(6):
        arr.append(list(map(int, input().rstrip().split())))
        
    maxSum = -100
    for i in range(4):
        for j in range(4):
            theSum = 0
            theSum += (arr[i][j] + arr[i][j+1] +arr[i][j+2] + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2])
            if theSum > maxSum:
                maxSum = theSum
    
    print(maxSum)
    
  • + 0 comments

    javascript

    `let max= -63

    for(let i=0; i<arr.length-2; i++){
        for(let j=0; j<arr.length-2; j++){
    
            let top = arr[i][j] + arr[i][j+1] + arr[i][j+2]
            let mid = arr[i+1][j+1]
            let bot = arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2]
            let currSum = top + mid + bot
            max = Math.max(max, currSum)
    
        }
    }
    
    console.log(max)`