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.
publicstaticinthourglassSum(List<List<Integer>>arr){// Write your code hereintmaxInteger=Integer.MIN_VALUE;for(introw=0;row<arr.size()-2;row++){for(intcol=0;col<arr.get(row).size()-2;col++){inttopRow=arr.get(row).get(col)+arr.get(row).get(col+1)+arr.get(row).get(col+2);intbottomRow=arr.get(row+2).get(col)+arr.get(row+2).get(col+1)+arr.get(row+2).get(col+2);intmiddleRow=arr.get(row+1).get(col+1);maxInteger=Math.max(maxInteger,topRow+bottomRow+middleRow);}}returnmaxInteger;}
2D Array - DS
You are viewing a single comment's thread. Return to all comments →