diff --git a/HourGlass.class b/HourGlass.class new file mode 100644 index 0000000..a181253 Binary files /dev/null and b/HourGlass.class differ diff --git a/HourGlass.java b/HourGlass.java new file mode 100644 index 0000000..cdf5ddc --- /dev/null +++ b/HourGlass.java @@ -0,0 +1,34 @@ +public class HourGlass { + + /* + * 1 1 1 0 0 0 + * 0 1 0 0 0 0 + * 1 1 1 0 0 0 + * 0 0 0 0 0 0 + * 0 0 0 0 0 0 + * 0 0 0 0 0 0 + */ + + public static void main(String[] args) { + + int[][] ar = { { 1, 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0 }, { 1, 1, 1, 0, 0, 0 }, { 0, 0, 2, 4, 4, 0 }, + { 0, 0, 0, 2, 0, 0 }, { 0, 0, 1, 2, 4, 0 } }; + System.out.println(sumInt(ar)); + } + + private static int sumInt(int[][] arr) { + int rows = arr.length; + int columns = arr[0].length; + + int total = -63; + for (int i = 0; i < rows - 2; i++) { + for (int j = 0; j < columns - 2; j++) { + int currentSum = arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] + + arr[i + 2][j + 1] + arr[i + 2][j + 2]; + total = Math.max(total, currentSum); + } + } + return total; + } + +}