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

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

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 >>>>>>>>>00 4 For the first test case no need to remove any substring, For the second test case we can remove (0)))) these two bold brackets, so the answer is 8. For the third test case we need to remove all the first brackets except last four, that makes the answer to 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!