Sakib and Shamim are good friends. As Sakib is a little naughty, every night before exam he disturbs…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
@Aritra15@mustafizz_22 Looks like the statement of this problem wasn’t very clear in its definition of what a valid subsequence is. I have tried to make some quick changes to it to make the statement clearer.
#include <bits/stdc++.h> #define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; #define ll long long #define vi vector #define pb push_back #define lp(i,a,b) for(int i = a ; i <= b ; i ++) #define rlp(i,a,b) for(int i = b ; i >= a ; i --) #define a_sort(v) sort(v.begin(), v.end()) #define d_sort(v) sort(v.rbegin(), v.rend()) #define pii pair<int,int>
using namespace std ;
I wrote a program that failed only on last test. I think the code is correct for this problem. can tell me, what am I missing to check?
def countValidParentheses(sp:str, vp_count:int):
if(sp=='\n' or sp==''):return 1
for i in range(0,len(sp)):
for j in range(i+1, len(sp)):
if((sp[i]== '(' and sp[j]==')')
or (sp[i]== '{' and sp[j]=='}')
or (sp[i]== '[' and sp[j]==']')):
vp_count+=1
return vp_count
from sys import stdin
strings=[]
for line in stdin:
# if(line=='\n'):break
strings.append(line.strip())
for string in strings:
result=countValidParentheses(sp=string,vp_count=0)
print(result)
I wrote a program that failed only on last test. I think the code is correct for this problem. can tell me, what am I missing to check?
def countValidParentheses(sp:str, vp_count:int):
if(sp=='\n' or sp==''):return 1
for i in range(0,len(sp)):
for j in range(i+1, len(sp)):
if((sp[i]== '(' and sp[j]==')')
or (sp[i]== '{' and sp[j]=='}')
or (sp[i]== '[' and sp[j]==']')):
vp_count+=1
return vp_count
from sys import stdin
strings=[]
for line in stdin:
# if(line=='\n'):break
strings.append(line.strip())
for string in strings:
result=countValidParentheses(sp=string,vp_count=0)
print(result)