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
ans = 0 NEW_LINE def countArraysUtil ( arr , X , K , xorVal ) : NEW_LINE INDENT global ans NEW_LINE if ( X == 0 ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( arr [ i ] > xorVal ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT if ( cnt >= K ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT return NEW_LINE DEDENT temp = arr [ 0 ] NEW_LINE arr . pop ( 0 ) NEW_LINE countArraysUtil ( arr , X - 1 , K , xorVal ) NEW_LINE arr . insert ( 0 , temp ) NEW_LINE temp = arr [ - 1 ] NEW_LINE arr . pop ( ) NEW_LINE countArraysUtil ( arr , X - 1 , K , xorVal ) NEW_LINE arr . append ( temp ) NEW_LINE arr [ 0 ] += 1 NEW_LINE countArraysUtil ( arr , X - 1 , K , xorVal ) NEW_LINE arr [ 0 ] -= 1 NEW_LINE arr [ len ( arr ) - 1 ] += 1 NEW_LINE countArraysUtil ( arr , X - 1 , K , xorVal ) NEW_LINE arr [ len ( arr ) - 1 ] -= 1 NEW_LINE DEDENT def countArrays ( arr , X , K ) : NEW_LINE INDENT xorVal = 0 NEW_LINE for i in range ( len ( arr ) ) : NEW_LINE INDENT xorVal = xorVal ^ arr [ i ] NEW_LINE DEDENT countArraysUtil ( arr , X , K , xorVal ) NEW_LINE print ( ans ) NEW_LINE DEDENT arr = [ 10 , 2 , 10 , 5 ] NEW_LINE X = 3 NEW_LINE K = 3 NEW_LINE countArrays ( arr , X , K ) NEW_LINE