function invertSubMatrix DC[01/06/2021]


function invertSubmatrix Daily Challenge [01/06/2021]


IMPORTANT: Do not write the main() function as it is already defined.


Example Input/Output 1:

Input:

5 6

0 1 0 1 0 0

0 1 1 0 0 0

1 1 0 0 1 0

1 1 0 1 0 0

0 1 1 1 0 0

2 3

3


Output:

0 1 0 1 0 0

0 1 0 1 1 0

1 1 1 1 0 0

1 1 1 0 1 0

0 1 1 1 0 0


Explanation:

Here K=3, so the size of the submatrix is 3x3. The position of the top-left cell is (2, 3).

The submatrix is highlighted below.

0 1 0 1 0 0

0 1 1 0 0 0

1 1 0 0 1 0

1 1 0 1 0 0

0 1 1 1 0 0

After inverting the values in the submatrix, the matrix becomes

0 1 0 1 0 0

0 1 0 1 1 0

1 1 1 1 0 0

1 1 1 0 1 0

0 1 1 1 0 0


Example Input/Output 2:

Input:

6 4

0 0 1 0

0 1 0 0

1 1 0 1

1 1 1 1

0 0 0 1

1 1 0 0

3 1

4


Output:

0 0 1 0

0 1 0 0

0 0 1 0

0 0 0 0

1 1 1 0

0 0 1 1

void invertSubmatrix(int R, int C, int matrix[R][C], int sRow, int sCol, int K)

{sRow--;

sCol--;

int eRow=sRow+K;

int eCol=sCol+K;

for(int i=sRow;i<eRow;i++)

{

    for(int j=sCol;j<eCol;j++)

    {

        matrix[i][j]= !matrix[i][j];

    }

}


}

Comments

Popular posts from this blog

alphabet matrix minimum sum path

C--Starter-part007---skillrack