- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
Latest commit
38 lines (33 loc) · 1.06 KB
/
Copy pathsolution.java
File metadata and controls
38 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
importjava.io.*;
// https://github.com/Utkarsh299-tech
importjava.math.*;
importjava.security.*;
importjava.text.*;
importjava.util.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
int[][] arr = newint[6][6];
for(introw = 0; row < 6; row++) {
for(intcol = 0; col < 6; col++) {
arr[row][col] = scan.nextInt();
}
}
scan.close();
System.out.println(maxHourGlass(arr));
}
publicstaticintmaxHourGlass(int[][] arr) {
intmax = Integer.MIN_VALUE;
for(introw = 0; row < 4; row++) {
for(intcol = 0; col < 4; col++) {
intsum = findSum(arr, row, col);
max = Math.max(max, sum);
}
}
returnmax;
}
privatestaticintfindSum(int[][] arr, intr, intc) {
intsum = arr[r+0][c+0] + arr[r+0][c+1] + arr[r+0][c+2] + arr[r+1][c+1] + arr[r+2][c+0] + arr[r+2][c+1] + arr[r+2][c+2];
returnsum;
}
}