Answered step by step
Verified Expert Solution
Question
1 Approved Answer
these bellow 2 pictures are one question. I need the code so please solve it with coding Given a bracket sequence which only contains opening
these bellow 2 pictures are one question. I need the code so please solve it with coding 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
these bellow 2 pictures are one question.
I need the code so please solve it with coding
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started