PARENTHESIS SEQUENCE Solutions BVPCSI03

PARENTHESIS SEQUENCE Solutions BVPCSI03

‘(‘ and ‘)′ are known as enclosure. An arrangement containing bracket is given however it’s not in a request that you like (or perhaps it is). To fix the given arrangement you can move all things considered one bracket from its unique spot in the succession to some other position. You can’t change over an open bracket into a shut one for example you can’t switch a section. We should call the arrangement you need a decent grouping. 

A decent arrangement (s) can be: s is vacant s is equivalent to “(t)”, where t is a decent arrangement. s is equivalent to t1.t2, for example connection of t1 and t2, where t1 and t2 are acceptable successions. 

Forexample, “(()())”,”()” are right, while “)(” and “())” are definitely not. 

Attempt to fix the aftereffect and comprehend whether you can move one section so the succession gets right or not. 

Info First of line of info contains a solitary number n — length of the arrangement. 

Second line of the info contains section arrangement of length n, containing images “(” and “)”. 

Yield Print “Yes” on the off chance that you can make the arrangement right moving all things considered one section. In any case print “No”. 

 

Limitations 

(1<=n<=200000) 

 

Test input 

)( 

 

Test yield 

Truly 

 

Test input 

(() 

 

Test yield 

No 

 

Test input 

() 

 

Test yield 

Truly 

 

Test input 

10 

)))))((((( 

 

Test yield 

No 

 

Clarification: 

In the main model, you can move first section as far as possible, consequently transforming the succession into “()”, which is right section grouping. 

In the subsequent model, it is highly unlikely to move all things considered one section with the goal that the arrangement gets right. 

In the third model, the succession is as of now right and there’s no compelling reason to move sections.

 
CODE PYTHON 3.6 :
 

 

 
n = int(raw_input())
b = list(raw_input())[:n]
c = []
if len(b) % 2 == 0:
    for e in b:
        if c:
            if c[-1] == ‘(‘ and e == ‘)’:
                c = c[:-1]
                continue
        c.append(e)
    if len(c) == 2 and not c[0] == c[1]:
        print(‘Yes’)
    elif len(c) == 0:
        print(‘Yes’)
    else:
        print(‘No’)
else:
    print(‘No’)

 

 

 

March Long Challenge 2021 Solutions

April Long Challenge 2021 Solutions

Codechef Long Challenge Solutions

February Long Challenge 2021

1. Frog Sort Solution Codechef

2. Chef and Meetings Solution Codechef

3. Maximise Function Solution Codechef

4. Highest Divisor Solution Codechef

5. Cut the Cake Challenge Solution Codechef

6. Dream and the Multiverse Solution Codechef

7. Cell Shell Solution Codechef

8. Multiple Games Solution Codechef

9. Another Tree with Number Theory Solution Codechef

10. XOR Sums Solution Codechef

11. Prime Game Solution CodeChef

12. Team Name Solution Codechef

January Long Challenge 2021

November Challenge 2020 SOLUTION CodeChef

October Lunchtime 2020 CodeChef SOLUTIONS

RELATED :

Related :

Related :

Leave a Comment

close
error: Content is protected !!