Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is to find length of the longest valid parenthesis substring. #366

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Input :
The first line contains a value T, which denotes the number of test cases. Then T test cases follow .The first line of each test case contains a value N. The next line contains 2*N+2 space separated integers.

Output :
Print in a new line the two numbers in ascending order.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
t=int(input())
while t!=0:
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=list(set(l))

for i in range(0,len(s)):
if l.count(s[i])%2!=0:
print(s[i],end=" ")
print()
t=t-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.

Input:
First line contains number of test cases T. Each test case have one line string S of character '(' and ')' of length N.

Constraints:
1 <= T <= 500
1 <= N <= 105

Example:
Input:
2
((()
)()())

Output:
2
4

Explanation:
Testcase 1: Longest valid balanced parantheses is () and its length is 2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if __name__=="__main__":
t=int(input())

while t!=0:
s=list(input())
ar=[]
c=0
for i in range(0,len(s)):
if s[i]==")":
if len(ar)!=0:

if ar[-1]=="(":
c=c+2
ar.pop(len(ar)-1)

else:
ar.append(s[i])
#print(ar)
print(c)
t=t-1