-
Notifications
You must be signed in to change notification settings - Fork 5
/
TwoDArrayDS.java
32 lines (29 loc) · 898 Bytes
/
TwoDArrayDS.java
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
package hackerrank;
public class TwoDArrayDS {
// Complete the hourglassSum function below.
static int hourglassSum(int[][] arr) {
int sum = -100;
for(int i = 0; i<= 3; i++){
for(int j = 0; j <=3 ; j++){
int subSum = 0;
int k =0;
for(int m = i; m< i+3; m++){
for(int n= j ; n < j+3; n++){
if(k==1){
if(n==j+1){
subSum = subSum + arr[m][n];
}
}else{
subSum = subSum+ arr[m][n];
}
}
k++;
}
if(sum< subSum)
sum = subSum;
System.out.println("i:"+i + " j:"+j + " sum:"+ sum);
}
}
return sum;
}
}