Sort by

recency

|

3686 Discussions

|

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

  • + 0 comments

    My Java 8 Solution:

    public static int hourglassSum(List<List<Integer>> arr) {
            int max = Integer.MIN_VALUE;
            
            for (int row = 0; row < 4; row++) {
                for (int col = 0; col < 4; col++ ) {
                    int sum = arr.get(row).get(col) + arr.get(row).get(col + 1) + arr.get(row).get(col + 2) + arr.get(row + 1).get(col + 1) + arr.get(row + 2).get(col) + arr.get(row + 2).get(col + 1) + arr.get(row + 2).get(col + 2);
                    
                    if (sum > max) {
                        max = sum;
                    }
                }
            }
            
            return max;
        }
    
  • + 0 comments

    Here is problem solution in Python 2 and Python 3 programming https://datastructure.us/hackerrank-2d-array-ds-python-solution.html