Construct an array from XOR of all elements of array except element at same index | function to construct new array ; calculate xor of array ; update array ; Driver code ; print result
function constructXOR ( A , n ) { let XOR = 0 ; for ( let i = 0 ; i < n ; i ++ ) XOR ^= A [ i ] ; for ( let i = 0 ; i < n ; i ++ ) A [ i ] = XOR ^ A [ i ] ; } let A = [ 2 , 4 , 1 , 3 , 5 ] ; let n = A . length ; constructXOR ( A , n ) ; for ( let i = 0 ; i < n ; i ++ ) document . write ( A [ i ] + " " ) ;