ou are given a string s, consisting of brackets of two types: '(', ')', '[' and ']'. A string is called a regular bracket sequence (RBS) if it's of one of the following type empty strin '(' + RBS + ')' '[' + RBS + ']' RBS + RBS where plus is a concatenation of two strings In one move you can choose a non-empty subsequence of the string s (not necessarily consecutive) that is an RBS, remove it from the string and concatenate the remaining parts without changing the order What is the maximum number of moves you can perfor

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

Correct answer will be upvoted else Multiple Downvoted. Computer science.

 

 

You are given a string s, consisting of brackets of two types: '(', ')', '[' and ']'.

 

A string is called a regular bracket sequence (RBS) if it's of one of the following type

 

empty strin

'(' + RBS + ')'

'[' + RBS + ']'

RBS + RBS

where plus is a concatenation of two strings

 

In one move you can choose a non-empty subsequence of the string s (not necessarily consecutive) that is an RBS, remove it from the string and concatenate the remaining parts without changing the order

 

What is the maximum number of moves you can perfor

 

Input

The first line contains a single integer t (1≤t≤1000) — the number of testcases

 

Each of the next t lines contains a non-empty string, consisting only of characters '(', ')', '[' and ']'. The total length of the strings over all testcases doesn't exceed 2⋅10

 

Output

For each testcase print a single integer — the maximum number of moves you can perform on a given string sut5..utm?r...;;g;s:on a given string s.

Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT