I need a function with the following signature:
public void requiredFunction(int[][] array, int row, int column) {
// code
}
The function should increment all the values in the same row, column and diagonal as array[row][column] (except array[row][column] itself).
Suppose I have the following 2D array:
int[][] array = {
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
};
Now when I call this function with the following values:
requiredFunction(array, 2, 2);
It should convert the array to:
array = {
1 0 1 0 1 0
0 1 1 1 0 0
1 1 0 1 1 1
0 1 1 1 0 0
1 0 1 0 1 0
0 0 1 0 0 1
};
If you think of the array as a chess board, then the function takes the position of the queen (row and column) and increments those places on the chess board, that the queen can move to.
Here is something shorter :