https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/description/
i immediately thought of using stack n space but there is actually constant space
def bracket_match(text):
ans =0
count_open = 0
for i in text:
if i=='(':
count_open+=1
else:
if count_open==0:
ans+=1
else:
count_open-=1
return count_open+ans