![]() |
VOOZH | about |
Given a square matrix (N X N), the task is to find the maximum XOR value of a complete row or a complete column.
Examples :
Input : N = 3
mat[3][3] = {{1, 0, 4},
{3, 7, 2},
{5, 9, 10} };
Output : 14
We get this maximum XOR value by doing XOR
of elements in second column 0 ^ 7 ^ 9 = 14
Input : N = 4
mat[4][4] = { {1, 2, 3, 6},
{4, 5, 6,7},
{7, 8, 9, 10},
{2, 4, 5, 11}}
Output : 12
A 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).
A efficient solution is we can traverse matrix only one time and calculate max XOR value .
Below is the implementation :
maximum XOR value : 12
Time complexity : O(N*N)
space complexity : O(1)