Count arrays having at least K elements exceeding XOR of all given array elements by X given operations | Stores the final answer ; Utility function to count arrays having at least K elements exceeding XOR of all given array elements ; If no operations are left ; Stores the count of possible arrays ; Count array elements are greater than XOR ; Stores first element ; Delete first element ; Recursive call ; Insert first element into vector ; Stores the last element ; Remove last element from vector ; Recursive call ; Push last element into vector ; Increment first element ; Recursive call ; Decrement first element ; Increment last element ; Recursive call ; Decrement last element ; Function to find the count of arrays having atleast K elements greater than XOR of array ; Stores the XOR value of original array ; Traverse the vector ; Print the answer ; Given vector ; Given value of X & K
let ans = 0 ; function countArraysUtil ( arr , X , K , xorVal ) { if ( X == 0 ) { let cnt = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] > xorVal ) cnt ++ ; } if ( cnt >= K ) ans ++ ; return ; } let temp = arr [ 0 ] ; arr . shift ( ) ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr . unshift ( temp ) ; temp = arr [ arr . length - 1 ] ; arr . pop ( ) ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr . push ( temp ) ; arr [ 0 ] ++ ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr [ 0 ] -- ; arr [ arr . length - 1 ] ++ ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr [ arr . length - 1 ] -- ; } function countArrays ( arr , X , K ) { let xorVal = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) xorVal = xorVal ^ arr [ i ] ; countArraysUtil ( arr , X , K , xorVal ) ; document . write ( ans ) ; } let arr = [ 10 , 2 , 10 , 5 ] ; let X = 3 , K = 3 ; countArrays ( arr , X , K ) ;