Given a word composed of opening and closing parentheses and brackets, we can do two operations:
Rotate a parentheses or bracket. That is, you can replace ( for ), ) for (, [ for ] and ] for [. This operation has cost 1
Replace a parentheses for a bracked and viceversa without changing its orientation. That is, change ( for [, ) for ], [ for ( and ] for ). This operation has cost 2.
Which is the minimum cost to balance the given word properly? For example, given ]( we can achieve [] by rotating twice and replacing once, with a total cost of 4