We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args)throwsIOException{Scanners=newScanner(System.in);int[][]arr=newint[6][6];for(inti=0;i<6;i++){for(intj=0;j<6;j++){arr[i][j]=s.nextInt();}}System.out.println(largestHourGlass(arr));}publicstaticintlargestHourGlass(int[][]arr){intlargestHourGlass=Integer.MIN_VALUE;for(inti=1;i<=4;i++){for(intj=1;j<=4;j++){intsum=arr[i][j]+arr[i+1][j+1]+arr[i-1][j-1]+arr[i+1][j-1]+arr[i-1][j+1]+arr[i-1][j]+arr[i+1][j];if(sum>largestHourGlass){largestHourGlass=sum;}}}returnlargestHourGlass;}//Reduced Complexity and less calculations}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java 2D Array
You are viewing a single comment's thread. Return to all comments →