PROBLEM LINK:Author: Bruno Oliveira DIFFICULTY:EASY PREREQUISITES:ADHOC PROBLEM:Given a bracket sequence, print the length of largest prefix that is a regular bracket sequence. EXPLANATION:A regular bracket sequence is defined as follows: If S is regular bracket sequence, for any i, number of closing brackets in S[0,i] should not exceed number of opening brackets. Also, if number of opening brackets is equal to number of closing brackets in S[0,i], S[0,i] is a regular bracket sequence.
Complexity: O(N). AUTHOR'S AND TESTER'S SOLUTIONS:
This question is marked "community wiki".
asked 12 May '14, 15:09

can i get sometest cases want to figure out where i am getting wrong, comipler of codeshef was flashing WRONG ANSWER answered 12 May '14, 17:39
1
You assume, that max input length is 100, why? See the second test case  http://ideone.com/Xxe1sf (answer is not 4 for sure)
(12 May '14, 17:59)
http://ideone.com/LjfGNp Can you help me where i m getting wrong thank you so much
(12 May '14, 19:04)
1
combination of statements
is strange isn't it?
(13 May '14, 04:10)
Actually, i used to work on Turbo c++ and it used to work on it. and also i am new to codeshef. But Yes It seems strange, http://ideone.com/ObhNFA, its working now but , time limit exceed, but i m trying to develop better logic.
(13 May '14, 12:40)

Can somebody please tell me the mistake that I did in this C code: http://ideone.com/HcmfNJ Got a WA.. :'( answered 12 May '14, 23:21
(13 May '14, 00:21)
Thanks a lot!
(13 May '14, 01:07)
Hadn't understood the question clearly..
(13 May '14, 01:08)

Can anyone post a java implementation for this? answered 13 May '14, 01:44
Mine is here  http://www.codechef.com/viewsolution/3815607
(13 May '14, 02:54)

Can anyone tell which case i am leaving ?? Have tried many times but cant get it Accepted. answered 14 May '14, 13:38
Your code is not working on ideone, can you fix it? http://ideone.com/1AnFUY I used your last submission in practice...
(14 May '14, 18:15)

Please give a test case where my code fails for compilers and parsers [http://www.codechef.com/viewsolution/3876116] the above link is the code where i had written in java answered 14 May '14, 17:47
You was kind of lucky, your code is not working on ideone I had to change
to
and the code returns 0 4 0 for input from problem statement http://ideone.com/UyDMNu , can you fork it and fix it on ideone?
(14 May '14, 18:11)

why im getting WA for this. please help me with this thanks in advance!! http://www.codechef.com/viewsolution/3900904 answered 11 Jun '14, 10:25
try this test case <<>.The answer should be 0 , but ur code gives 2.
(11 Jun '14, 10:47)
@rishab why so coz <<> last two brackets are matching which is the case with the official test case of <>>> which gives 2 as output. plz clarify it :(
(11 Jun '14, 11:52)
(11 Jun '14, 12:29)
thanku got it :P
(16 Jun '14, 11:28)

what do you mean by adhoc? ( one of prerequisites) answered 11 Jun '14, 11:26

Can someone provide a solution for the same above problem if the word prefix was removed. I am getting considerable difficulties in doing this version. Eg. for <<<<<<<<> output:2 , for <><><<<<<<<<<> output:4. My problem is that how do we track whether the new contiguous sub sequence extends the previous one or not. As in <<>><<>> output:8 but for <<>><<<>> output:4. Please help! answered 13 Jun '14, 13:51

you can solve the problem using divide and conquer approach with a segment tree. At each node of the segment tree, store the following 5 variables: l > the maximum positive sum from right end So, for a node N, the best can be calculated as the maximum of b values of the children, or taking the joint of the r value of the right child and l value of the left child. if mod of l of left child is less than mod of r of right child, then just find the index in the right child where the prefix sum is equal to l. similar procedure if mod of r is smaller than mod of l. this is work in NlogN. answered 13 Jun '14, 14:32

http://www.codechef.com/viewsolution/4150026 .WA checked with all cases discused above .Thanks in advance answered 28 Jun '14, 02:22

For which test case am i getting WA ?. Please someone answer . my subbmission http://www.codechef.com/viewsolution/4167497 Thanks in advance answered 30 Jun '14, 20:52

Why do we need to calculate "ans=max(ans,i+1)"? We can just write "ans=i+1" which will also work. answered 27 Apr '15, 14:41

Answer is hidden as author is suspended. Click here to view.
answered 02 May '15, 12:06

https://www.codechef.com/viewsolution/15906400 i dn know why i am getting WA please anyone suggest some edge cases . answered 20 Oct '17, 20:57

answered 18 Nov '17, 21:41

def check(s): answered 16 Feb '18, 17:17

include<iostream>include<bits stdc++.h="">include<string>using namespace std; typedef unsigned long long int ull; define F firstdefine S seconddefine nl printf("\n");define pb push_backdefine mp make_pairdefine f(i,a,b) for(int i=a;i<b;i++)define MOD 1000000007define fastscan ios_base::sync_with_stdio(0); cin.tie(NULL);int main(int argc, char const *argv[]) {
} //Anybody tell me whats wrong in this code.. answered 20 Feb '18, 20:50

I have implemented this algorithm in Go and tried to run it but getting a time limit exceed error. But the same algorithm I've implimented in Python3 and run it and it accepted. Is Go compiler not well implemented? answered 21 Feb '18, 22:15

Could anyone please tell me what I am missing in my code? Getting WA. Have attached my own test cases. https://ideone.com/6HQabT answered 17 Mar '18, 22:00

Can anyone tell me what is wrong with this solution? https://ideone.com/O4w7qo answered 23 May '18, 20:26

include<bits stdc++.h="">define ll long long intusing namespace std; int main() { ll t; cin>>t; while(t) { //ll cnt=0; stack <char> s; string s1; cin>>s1; ll n=s1.size(); if(n==1s1[0]=='>') { cout<<0<<endl; continue;="" }="" int="" i="0;" ll="" cnt="0,res=0;" while(s1[i]!="\\0" )="" {="" if(s1[i]="='<')" {="" s.push(s1[i]);="" cnt++;="" }="" else="" if(s1[i]="='">') { s.pop(); } if(s.empty()) { res+=cnt; cnt=0; } i++; } cout<<res*2<<endl;
} what is the prob with my code ?? i have checked most of the testacases all are passing still am getting wa. please help me with testcases answered 12 Jun '18, 00:15

Rest is your implementation of code you can check my code link text answered 12 Jun '18, 19:13

both author and setter has wrong ans. Check for ">><>" this. answer should be 2. but your solution shows, 0. answered 28 Jun '18, 18:12

Can anybody tell me where the mistake is in this code. I'm getting WA https://ideone.com/RDULCj answered 07 Dec '18, 13:03

can someone please tell me what's wrong and why it does not get submitted successfully when it gives correct answer to the test case given in the problem. code : https://ideone.com/H6AA9w answered 04 Feb, 22:16
