This is a java solution to one of hackerrank problem given in below link. https://www.hackerrank.com/challenges/2d-arrayI know it's not optimized, can anyone help me to refactor and optimize?Task:Calculate the hourglass sum for every hourglass in , then print the maximum hourglass sum.Note: If you have already solved the Java domain's Java 2D Array challenge, you may wish to skip this challenge.Input Format:There are  lines of input, where each line contains  space-separated integers describing 2D Array ; every value in  will be in the inclusive range of  to .Output FormatPrint the largest (maximum) hourglass sum found in Array.Sample Input1 1 1 0 0 00 1 0 0 0 01 1 1 0 0 00 0 2 4 4 00 0 0 2 0 00 0 1 2 4 0Sample Output19solution:public class TestHourGlass {        public static void main(String[] args) {                Scanner in = new Scanner(System.in);                int arr[][] = new int[6][6];                 int hourGlassSum[] = new int[16];                int pos = 0;                //Reads data from user input and store in 6*6 Array                for (int arr_i = 0; arr_i < 6; arr_i++) {                    for (int arr_j = 0; arr_j < 6; arr_j++) {                        arr[arr_i][arr_j] = in.nextInt();                    }                }                //Find each possible hourGlass and calculate sum of each hourGlass                for (int i = 0; i < 4; i++) {                    for (int j = 0; j < 4; j++) {                        hourGlassSum[pos] = calculateHourGlassSum(arr, i, i + 2, j, j + 2);                        pos++;                    }                }                System.out.println(findmax(hourGlassSum));            }            /**             * @param arr              * @param pos1 - Row startPoint             * @param pos2 - Row endPoint             * @param pos3 - column startPoint             * @param pos4 - column endPoint             * @return             */            public static int calculateHourGlassSum(int arr[][], int pos1, int pos2, int pos3, int pos4) {                int sum = 0;                int exclRowNum = pos1 + 1;                int exclColNum1 = pos3;                int exclColNum2 = pos4;                for (int arr_i = pos1; arr_i <= pos2; arr_i++) {                    for (int arr_j = pos3; arr_j <= pos4; arr_j++) {                        sum = sum + arr[arr_i][arr_j];                    }                }                sum = sum - (arr[exclRowNum][exclColNum1] + arr[exclRowNum][exclColNum2]);                return sum;            }            /**             * @param arr             * @return max elem of Array             */            public static int findmax(int arr[]) {                int max = arr[0];                for (int i = 0; i < arr.length; i++) {                    if (arr[i] >= max)                        max = arr[i];                }                return max;            }}
java 2d Array HourGlass Problem from hackerrank
java;algorithm;programming challenge;array