human
Minimum number that can be obtained by applying ' + ' and ' * ' operations on array elements | Function to find the smallest number that can be obtained after applying the arithmetic operations mentioned in the string S.
Stores the count of multiplication operator in the string.
Store the required result.
Iterate in the range to create the mask.
Checking the number of bits that are set in the mask.
Check if the number of bits that are set in the mask is multiplication operation.
Storing the elements that is to be added.
Apply the multiplications operation first.
If sign is ' * ' , then multiply last element of deque with arr [ i ].
append last multiplied element in the deque.
If the element is to be added , then add it to the deque.
Add all the element of the deque.
Minimize the answer with the given sum.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to minimum number that can be obtained by applying ' + ' and ' * ' operations on array elements and the other steps required.
 def minimumSum ( A , N , S ) :
	mul = 0
	for i in range ( len ( S ) ) :
		if ( S [ i ] == " * " ) :
			mul += 1
	ans = 1000000
	for i in range ( 1 << ( N - 1 ) ) :
		cnt = 0
		v = [ ]
		for j in range ( N - 1 ) :
			if ( ( 1 << j ) & i ) :
				cnt += 1
				v . append ( " * " )
			else :
				v . append ( " + " )
		if ( cnt == mul ) :
			d = [ ]
			d . append ( A [ 0 ] )
			for j in range ( N - 1 ) :
				if ( v [ j ] == " * " ) :
					x = d [ len ( d ) - 1 ]
					d . pop ( )
					x = x * A [ j + 1 ]
					d . append ( x )
				else :
					d . append ( A [ j + 1 ] )
			sum = 0
			while ( len ( d ) > 0 ) :
				x = d [ 0 ]
				sum += x
				d . pop ( 0 )
			ans = min ( ans , sum )
	return ans
A = [ 2 , 2 , 2 , 2 ]
S = " * * + "
N = len ( A )
print ( minimumSum ( A , N , S ) )