Minimum size of the array with MEX as A and XOR of the array elements as B | Function to find the minimum size of array with given MEX and XOR ; Find the XOR of values from 0 to A - 1 ; If A is a multiple of 4 ; If A % 4 gives remainder 1 ; If A % 4 gives remainder 2 ; Initializing array size by A ; If XOR of all values of array is equal to B ; If the required integer to be added is equal to A ; Else any integer can be added ; Driver Code
function minimumSizeArr ( A , B ) { let currXor = 0 ; let reminder = ( A - 1 ) % 4 ; if ( reminder == 0 ) currXor = A - 1 ; else if ( reminder == 1 ) currXor = 1 ; else if ( reminder == 2 ) currXor = A ; let minSize = A ; if ( currXor == B ) return minSize ; else if ( currXor ^ ( B == A ) ) return minSize + 2 ; else return minSize + 1 ; } let A = 1 ; let B = 999 ; document . write ( minimumSizeArr ( A , B ) ) ;