You are viewing a single comment's thread. Return to all comments →
Best Solution with Time Complexity O(n)
int sum; int maxi = -100000; int x = 0; int y = 0; for (int k = 1; k <= 16; k++) { sum = arr[y][x] + arr[y][x + 1] + arr[y][x + 2] + arr[y + 1][x + 1] + arr[y + 2][x] + arr[y + 2][x + 1] + arr[y + 2][x + 2]; x++; if ((k % 4 == 0)) { x = 0; y++; } if(sum > maxi) maxi = sum; } System.out.println(maxi);
Seems like cookies are disabled on this browser, please enable them to open this website
Java 2D Array
You are viewing a single comment's thread. Return to all comments →
Best Solution with Time Complexity O(n)