Create an array such that XOR of subarrays of length K is X | C ++ implementation to Create an array in which the XOR of all elements of each contiguous sub - array 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void constructArray ( int N , int K , int X ) { vector < int > ans ( K , 0 ) ; ans [ 0 ] = X ; for ( int i = 0 ; i < N ; ++ i ) { cout << ans [ i % K ] << " ▁ " ; } cout << endl ; } int main ( ) { int N = 5 , K = 2 , X = 4 ; constructArray ( N , K , X ) ; return 0 ; }