Question: these bellow 2 pictures are one question. Given a bracket sequence which only contains opening and ending of first bracket 'l' and ')'. A bracket


Given a bracket sequence which only contains opening and ending of first bracket 'l' and ')'. A bracket sequence is called balanced if it follows three rules, 1. Empty sequence is a balanced bracket sequence 2. If S is a balanced bracket sequence then (S) is also a balanced bracket sequence. 3. If S and T are balanced bracket sequences then ST is also balanced bracket sequence. (By ST we mean concatenation of S and T) For example (1000) is a balanced bracket sequence where () is not. Now given a bracket sequence (not necessarily balanced), you need to make it balanced but you have only one operation, you can remove a consecutive subsequence from the bracket sequence. And you can use this operation only once or zero times. Can you find the maximum length of balanced bracket sequence after the operation? Input The first line of the input contains a single integer t(1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
