Find the minimum cost to balance a bracket string using pencil-character swaps and flips.
Unlock detailed company stats for this questionUpgrade
Given a string of '[' and ']' and a mask string where 'P' marks permanent characters (cannot be moved or modified) and 'p' marks pencil characters. On pencil characters you may swap any two (cost 1) or change '[' to ']' or vice versa (cost 2). Return the minimum total cost to make the bracket sequence balanced, or -1 if impossible.
Format · Online assessment.
Community answers
No answers contributed by the community yet.
Related questions
Find the minimum number of swaps to balance a parentheses string.Check if a bracket string is balanced and, if not, find the minimum reversals needed to balance it.Find the minimum number of turns to type a string using same-character overwrites.Related courses

Course

Course
Course
