Java - How to Solve this 2D Array Hour Glass?
<p>I am working on a problem where I've to print the largest sum among all the hourglasses in the array. You can find the details about the problem <a href="https://www.hackerrank.com/challenges/2d-array" rel="noreferrer">here-</a></p>

<p><strong>What I tried:</strong></p>

<pre><code>public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int arr[][] = new int[6][6];
        for (int arr_i = 0; arr_i &lt; 6; arr_i++) {
            for (int arr_j = 0; arr_j &lt; 6; arr_j++) {
                arr[arr_i][arr_j] = in.nextInt();
            }
        }

        int sum = 0;
        int tmp_sum = 0;
        for (int arr_i = 0; arr_i &lt; 4; arr_i++) {
            for (int arr_j = 0; arr_j &lt; 4; arr_j++) {
                if (arr[arr_i][arr_j] &gt; 0) {
                    sum = sum + (arr[arr_i][arr_j]) + (arr[arr_i][arr_j + 1]) + (arr[arr_i][arr_j + 2]);
                    sum = sum + (arr[arr_i + 1][arr_j + 1]);
                    sum = sum + (arr[arr_i + 2][arr_j]) + (arr[arr_i + 2][arr_j + 1]) + (arr[arr_i + 2][arr_j + 2]);
                    if (tmp_sum &lt; sum) {
                        tmp_sum = sum;
                    }
                    sum = 0;
                }
            }
        }
        System.out.println(tmp_sum);
    }
}
</code></pre>

<p><strong>Input:</strong></p>

<pre><code>1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 9 2 -4 -4 0
0 0 0 -2 0 0
0 0 -1 -2 -4 0
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>12
</code></pre>

<p><strong>Expected Output:</strong></p>

<pre><code>13
</code></pre>

<p><strong>Screenshot:</strong>
<a href="https://i.stack.imgur.com/rnrhW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/rnrhW.png" alt="enter image description here"></a></p>

<p>I don't know where I'm doing wrong. I cannot understand why the expected output is <code>13</code>. According to the description given in the problem it should be <code>10</code>. Is this a wrong question or my understanding about this is wrong?</p>