Create an array such that XOR of subarrays of length K is X | Java 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 an array of size K , initialised with 0 ; Initialising the first element with the given XOR ; Driver code
class GFG { public static void constructArray ( int N , int K , int X ) { int [ ] ans = new int [ K ] ; ans [ 0 ] = X ; for ( int i = 0 ; i < N ; ++ i ) { System . out . print ( ans [ i % K ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 5 , K = 2 , X = 4 ; constructArray ( N , K , X ) ; } }