Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions