human
Minimum number of Parentheses to be added to make it valid | Function to return required minimum number.
maintain balance of string.
It is guaranteed bal >= - 1.
Driver code.
Function to print required answer"
Solution in Python:
assistant
#Here is code to minimum number of Parentheses to be added to make it valid and the other steps required.
 def minParentheses ( p ) :
	bal = 0
	ans = 0
	for i in range ( 0 , len ( p ) ) :
		if ( p [ i ] == ' ( ' ) :
			bal += 1
		else :
			bal += - 1
		if ( bal == - 1 ) :
			ans += 1
			bal += 1
	return bal + ans
if __name__ == ' _ _ main _ _ ' :
	p = " ( ) ) "
	print ( minParentheses ( p ) )