Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1 (Array) A bracket sequence is a string that contains only characters' (' and ')'. A correct bracket sequence is a bracket sequence that
Problem 1 (Array) A bracket sequence is a string that contains only characters' (' and ')'. A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters 'l' and '+' between the original characters of the sequence. For example, bracket sequences' () ()' and '(0)' are correct. The resulting expressions of these sequences are: '(1)+(1)' and '((1+1)+1)'. However, '(',') (', and '(' are incorrect bracket sequences. You are given a bracket sequence s (5152...S.), where s; denotes the type of its bracket (open or close). It is not mandatory that s is necessarily correct. Your task is to determine the number of i's such that siSit1... SnS1S2...Si-1 is a correct bracket sequence. Input format The single line contains sequence s. Output format Print the number of shifts denoting the correct bracket sequence. Constraints Is 55x105 Sample Input ) 000 Sample Output 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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