File tree 1 file changed +42
-0
lines changed
1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .io .*;
2
+ import java .math .*;
3
+ import java .security .*;
4
+ import java .text .*;
5
+ import java .util .*;
6
+ import java .util .concurrent .*;
7
+ import java .util .function .*;
8
+ import java .util .regex .*;
9
+ import java .util .stream .*;
10
+ import static java .util .stream .Collectors .joining ;
11
+ import static java .util .stream .Collectors .toList ;
12
+
13
+ class Result {
14
+
15
+ /*
16
+ * Complete the 'hourglassSum' function below.
17
+ *
18
+ * The function is expected to return an INTEGER.
19
+ * The function accepts 2D_INTEGER_ARRAY arr as parameter.
20
+ */
21
+
22
+ public static int hourglassSum (List <List <Integer >> arr ) {
23
+ ArrayList <Integer > Sums = new ArrayList <>();
24
+ int Sum = 0 , i =0 , j =0 , k =0 ;
25
+ while (i < 4 ){
26
+ int babysum = 0 ;
27
+ babysum += (arr .get (i ).get (j ) + arr .get (i ).get (j +1 ) + arr .get (i ).get (j +2 ));
28
+ babysum += arr .get (i +1 ).get (j +1 );
29
+ babysum += (arr .get (i +2 ).get (j ) + arr .get (i +2 ).get (j +1 ) + arr .get (i +2 ).get (j +2 ));
30
+ j ++;
31
+ Sums .add (babysum );
32
+
33
+ if (j == 4 ){
34
+ i ++;
35
+ j =0 ;
36
+ }
37
+ }
38
+
39
+ return Collections .max (Sums );
40
+ }
41
+
42
+ }
You can’t perform that action at this time.
0 commit comments