## Monday, November 21, 2016

### Maximum XOR value in matrix - GeeksforGeeks

Maximum XOR value in matrix - GeeksforGeeks
Given a square matrix (N X N), the task is to find the maximum XOR value of a complete row or a complete column.

simple solution of this problem is we can traverse the matrix twice and calculate maximum xor value row wise & column wise ,and at last return the maximum between (xor_row , xor_column).
efficient solution is we can traverse matrix only one time and calculate max XOR value .
1. Start traverse the matrix and calculate XOR at each index row and column wise. We can compute both values by using indexes in reverse way. This is possible because matrix is a square matrix.
2. Store the maximum of both.
`const` `int` `MAX = 1000;`

`// function return the maximum xor value that is`
`// either row or column wise`
`int` `maxXOR(``int` `mat[][MAX], ``int` `N)`
`{`
`    ``// for row xor and column xor`
`    ``int` `r_xor, c_xor;`
`    ``int` `max_xor = 0;`

`    ``// traverse matrix`
`    ``for` `(``int` `i=0 ; i<N ; i++)`
`    ``{`
`        ``r_xor = 0, c_xor = 0;`
`        ``for` `(``int` `j=0 ; j< N ; j++)`
`        ``{`
`            ``// xor row element`
`            ``r_xor = r_xor^mat[i][j];`

`            ``// for each column : j is act as row & i`
`            ``// act as column xor column element`
`            ``c_xor = c_xor^mat[j][i];`
`        ``}`

`        ``// update maximum between r_xor , c_xor`
`        ``if` `(max_xor < max(r_xor,c_xor))`
`            ``max_xor =  max(r_xor,c_xor);`
`    ``}`

`    ``// return maximum xor value`
`    ``return` `max_xor;`
`}`