Sort by

recency

|

3688 Discussions

|

  • + 0 comments

    My python sollution`

    def hourglassSum(a):
        ma = -float('inf')
        for i in range(1,5):
            for j in range(1,5):
                top = bottom = 0
                for dy in [-1,0,1] :
                    top += a[i-1][j+dy]
                    bottom += a[i+1][j+dy]
                ma = max(ma,top + a[i][j] + bottom)
        return ma
    
  • + 0 comments

    A solution in Python that respects the constraints proposed by the challenge (and focuses on readability):

    """
    Constraints:
        -9 <= arr[i][j] <= 9
        0 <= i,j <= 5
    """
    
    def get_hour_glass_sum(arr: List[int], x: int, y: int) -> int:
        first_line = sum([arr[x][y + i] for i in range(3)])
        second_line = arr[x + 1][y + 1]
        third_line = sum([arr[x + 2][y + i] for i in range(3)])
        
        return first_line + second_line + third_line
    
    def hourglassSum(arr):
        greater_sum = None
        
        for x in range(4):
            for y in range(4):
                current_sum = get_hour_glass_sum(arr, x, y)
                
                if greater_sum is None:
                    greater_sum = current_sum
                    continue
                
                greater_sum = max(current_sum, greater_sum)
                
        return greater_sum
    
  • + 0 comments

    this is my solution : Image

    **My Code In Java: **

    int temporary = Integer.MIN_VALUE;
            for( int i = 0; i < arr.size() - 2; i++){
                for( int j = 0 ; j < arr.size() - 2; j++){
                    int a = arr.get(i).get(j);
                    int b = arr.get(i).get(j+1);
                    int c = arr.get(i).get(j+2);
                    int d = arr.get(i+1).get(j+1);
                    int e = arr.get(i+2).get(j);
                    int f = arr.get(i+2).get(j+1);
                    int g = arr.get(i+2).get(j+2);
                    
                    int result = a + b + c + d + e + f + g;
                    if (result > temporary){
                        temporary = result;
                    }
                }
            }
            
            return temporary;
    
  • + 0 comments

    Here is the solution in C language. (Paste it in VS Code or format it (can also use gpt to format).

    include

    void input(int arr[6][6]) { for(int row = 0; row < 6; row++) { for(int col = 0; col < 6; col++) { scanf("%d", &arr[row][col]); } } } int highest_sum(int arr[6][6]) { // Basically, hourglass format is like. // These all alphabets are basically represent columns.
    // a1, a2, a3 // b1 // c1, c2, c3 int result_sum = -100, temp_sum = 0; // we have initialized result_sum with -100 not 0 because if the numbers are negative and first sum we get is also negative, so it will not get stored becuase of if condition. for(int row=0; row<4; row++) { for(int cols=0; cols<4; cols++) {
    temp_sum = arr[row][cols] + arr[row][cols+1] + arr[row][cols+2] + arr[row+1][cols+1] + arr[row+2][cols] + arr[row+2][cols+1] + arr[row+2][cols+2] ; //a1 + a2 + a3 + b1 +c1 + c2 + c3 if (temp_sum>result_sum) { // so that the bigger sum gets stored in the result. result_sum = temp_sum; } } } return result_sum; } int main() { int matrix[6][6]; int highest_hourglass_sum; input(matrix); //input function is created. highest_hourglass_sum = highest_sum(matrix); printf("%d",highest_hourglass_sum); return 0; } int main() { int matrix[6][6]; int highest_hourglass_sum; input(matrix); //input function is created. highest_hourglass_sum = highest_sum(matrix); printf("%d",highest_hourglass_sum); return 0; }

  • + 0 comments

    Your method of breaking down the 6x6 matrix into manageable 6x3 sections and using loops to calculate hourglass sums is a smart, structured solution—especially for fixed sizes. It's similar to how in Bowmasters, you might focus on specific strategies to collect gems efficiently within a known game mode or map. However, just like your matrix approach might not scale well for NxM matrices, a rigid strategy in Bowmasters might not adapt well across different challenges or updates. Flexibility is key in both cases for long-term success and efficiency.