Create an array such that XOR of subarrays of length K is X | Function to construct the array ; Creating a vector of size K , initialised with 0 ; Initialising the first element with the given XOR ; Driver code
function constructArray ( N , K , X ) { let ans = new Array ( K ) . fill ( 0 ) ; ans [ 0 ] = X ; for ( let i = 0 ; i < N ; ++ i ) { document . write ( ans [ i % K ] + " " ) ; } document . write ( " " ) ; } let N = 5 , K = 2 , X = 4 ; constructArray ( N , K , X ) ;