human
Give me a code to bitwise operations on Subarrays of size K and the other steps required given the following:
Bitwise operations on Subarrays of size K | Function to convert bit array to decimal number.
Function to find minimum values of each bitwise AND operation on element of subarray of size K.
Maintain an integer array bit of size 32 all initialized to 0.
Create a sliding window of size k.
Function call.
Perform operation to removed element.
Perform operation to add element.
Taking minimum value.
Return the result.
Driver Code.
Given array arr.
Given subarray size K.
Function call"
Solution in Python:
assistant
#Here is code to bitwise operations on Subarrays of size K and the other steps required.
 def build_num ( bit , k ) :
	ans = 0 ;
	for i in range ( 32 ) :
		if ( bit [ i ] == k ) :
			ans += ( 1 << i ) ;
	return ans ;
def minimumAND ( arr , n , k ) :
	bit = [ 0 ] * 32 ;
	for i in range ( k ) :
		for j in range ( 32 ) :
			if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) :
				bit [ j ] += 1 ;
	min_and = build_num ( bit , k ) ;
	for i in range ( k , n ) :
		for j in range ( 32 ) :
			if ( ( arr [ i - k ] & ( 1 << j ) ) > 0 ) :
				bit [ j ] -= 1 ;
		for j in range ( 32 ) :
			if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) :
				bit [ j ] += 1 ;
		min_and = min ( build_num ( bit , k ) , min_and ) ;
	return min_and ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 5 , 3 , 6 , 11 , 13 ] ;
	k = 3 ;
	n = len ( arr ) ;
	print ( minimumAND ( arr , n , k ) ) ;