text: Update answer by adding minimum of removing both unbalanced open and closed brackets or inserting closed unbalanced brackets to end of String
code: result += Math . min ( a * ( openUnbalanced + closedUnbalanced ) , b * closedUnbalanced ) ;