res to 0 (to count insertions) and right to 0 (to count the number of right parentheses needed).c in the string s.
c is '(', check if right is odd. If so, decrement right and increment res.right by 2, anticipating two ')' for each '('.c is ')', decrement right.right is negative after decrementing, increment right by 2 and res by 1.right to res to account for any remaining unbalanced parentheses.res as the minimum number of insertions needed.