# Day 11: 2D Arrays

# Day 11: 2D Arrays

+ 84 comments my solution

`int sum[] = new int[16]; int h = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { sum[h] = 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]; h++; } } Arrays.sort(sum); System.out.println(sum[15]);`

+ 8 comments I've a general question, the tab "Discussions" should be for discussing things but often i see people sharing their solutions which expose all the code and make the cheating possible, isn't there anyone like moderator or isn't there any rule that prevent such things? it's a total failure if a person doesn't learn on its own and copy paste someone's "posted" code and pass the challange.

+ 28 comments Python solution:

res = [] for x in range(0, 4): for y in range(0, 4): s = sum(arr[x][y:y+3]) + arr[x+1][y+1] + sum(arr[x+2][y:y+3]) res.append(s) print(max(res))

+ 6 comments For all struggling on the negative examples(#3 and #7), here is how to fix it in layman's terms. Set your variable for the highest sum to the lowest value a sum could be: -63. This makes it work because during the check if the sum of the current hourglass is greater than the current highest sum, it is failing because that negative number is lower than zero.

+ 7 comments Here is my solution in java:

`int max = -64, temp; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { temp = 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]; if (temp > max){ max = temp; } } } System.out.println(max);`

Sort 1743 Discussions, By:

Please Login in order to post a comment