You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation:
10
+
11
+
a b c
12
+
d
13
+
e f g
14
+
15
+
There are 16 hourglasses in . An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6.
16
+
17
+
Example
18
+
19
+
arr =
20
+
-9 -9 -9 1 1 1
21
+
0 -9 0 4 3 2
22
+
-9 -9 -9 1 2 3
23
+
0 0 8 6 6 0
24
+
0 0 0 -2 0 0
25
+
0 0 1 2 4 0
26
+
27
+
The 16 hourglass sums are:
28
+
29
+
-63, -34, -9, 12,
30
+
-10, 0, 28, 23,
31
+
-27, -11, -2, 10,
32
+
9, 17, 25, 18
33
+
The highest hourglass sum is 28 from the hourglass beginning at row 1, column 2:
34
+
35
+
0 4 3
36
+
1
37
+
8 6 6
38
+
Note: If you have already solved the Java domain's Java 2D Array challenge, you may wish to skip this challenge.
39
+
40
+
Function Description:
41
+
42
+
Complete the function hourglassSum in the editor below.
43
+
44
+
hourglassSum has the following parameter(s):
45
+
46
+
int arr[6][6]: an array of integers
47
+
Returns
48
+
49
+
int: the maximum hourglass sum
50
+
51
+
Input Format
52
+
Each of the 6 lines of inputs arr[i] contains 6 space-separated integers arr[i][j].
53
+
54
+
Constraints
55
+
-9 <= arr[i][j] <= 9
56
+
0 <= i,j <= 5
57
+
58
+
Output Format
59
+
Print the largest (maximum) hourglass sum found in arr.
0 commit comments