You are on page 1of 4

6/17/2014 COMPILER - Editorial - CodeChef Discuss

http://discuss.codechef.com/questions/42551/compiler-editorial 1/4
Followthisquestion
ByEmail:
Youarenotsubscribedtothisquestion.
subscribeme
(youcanadjustyournotification
settingsonyourprofile)
ByRSS:
Answers
AnswersandComments
Tags:
editorial 785
easy332
adhoc56
compiler37
may1410
Asked:12May,15:09
Seen:1,143times
Lastupdated:yesterday
Relatedquestions
RRSTONEEditorial
BALLSEditorial
ROCEditorial
OJUMPSEditorial
IITI14Editorial
PPNUMEditorial
LUCKY8Editorial
SUBSTREditorial
CHEFBMEditorial
DIRELEditorial
questions tags users badges unanswered ask a question about
krutarthkp800 1 LogOut
Theoldforumcanbeviewedhere.Seekhelp.
CodeChefDiscussion
SearchHere... questions tags users
7
1
adhocmay14easyeditorial compiler
Thisquestionismarked"communitywiki".
asked12May,15:09
darkshadows
2.7k548793
acceptrate:7%
edited12May,17:19
13Answers:
0
link | awardpoints answered12May,16:23
zitu_cuet
1
acceptrate:0%
COMPILEREditorial
PROBLEMLINK:
Practice
Contest
Author:BrunoOliveira
Tester:SergeyKulik
Editorialist:LalitKundu
DIFFICULTY:
EASY
PREREQUISITES:
ADHOC
PROBLEM:
Givenabracketsequence,printthelengthoflargestprefixthatisaregularbracketsequence.
EXPLANATION:
Aregularbracketsequenceisdefinedasfollows:
1.S=""isregular.
2.S="<"+S1">"isregular,ifS1isregular.
3.S=S1concatS2isregular,isS1andS2areregular.
IfSisregularbracketsequence,foranyi,numberofclosingbracketsinS[0,i]shouldnotexceednumberofopeningbrackets.
Also,ifnumberofopeningbracketsisequaltonumberofclosingbracketsinS[0,i],S[0,i]isaregularbracketsequence.
defcheck(s):
t=0,ans=0
fori=0toN1:
ifs[i]=='<':t++
else:
t
//Now,ift=0,means,thestrings[0,i]isvalid.
ift==0:ans=max(ans,i+1)
elseift<0:break//stringswholeisinvalid.
printans
Complexity:O(N).
AUTHOR'SANDTESTER'SSOLUTIONS:
Author'ssolution
Setter'ssolution
addnewcomment
1 2 next
CananyonetellmewhythiscodegivesWA??linktext
oldest newest mostvoted
1
Trythiscase:
1
6/17/2014 COMPILER - Editorial - CodeChef Discuss
http://discuss.codechef.com/questions/42551/compiler-editorial 2/4
0
link | awardpoints answered12May,17:39
gaurav_bhumika
1
acceptrate:0%
0
link | awardpoints answered12May,20:49
ashish1610
111137
acceptrate:11%
0
link | awardpoints answered12May,23:21
masif
1
acceptrate:0%
0
link | awardpoints answered13May,01:44
saopayne
11
acceptrate:0%
0
link | awardpoints answered13May,15:12
mjbpl
30625
acceptrate:5%
addnewcomment
canigetsometestcaseswanttofigureoutwhereiamgettingwrong,comiplerofcodeshefwasflashingWRONGANSWER
addnewcomment
CananyonetellmewhymythisPascalcodewasgivingwrongansbutsameimplementationinC++passed?
addnewcomment
CansomebodypleasetellmethemistakethatIdidinthisCcode:http://ideone.com/HcmfNJ
GotaWA..:'(
addnewcomment
Cananyonepostajavaimplementationforthis?
addnewcomment
Incidentallyasimilarquestionwasaskedonforumsafewmonth'sback.
(12May,16:26) mukit_mkbs
<<><>>
Outputshouldbe6
(12May,16:34) zitu_cuet
Thanksgotit!!!:P:P
(12May,17:59) betlista
1
Youassume,thatmaxinputlengthis100,why?
Seethesecondtestcasehttp://ideone.com/Xxe1sf(answerisnot4forsure)
(12May,19:04) gaurav_bhumika
http://ideone.com/LjfGNpCanyouhelpmewhereimgettingwrongthankyousomuch
(13May,04:10) betlista
1
combinationofstatements
char*a[500]
//...
a[m][j]
isstrangeisn'tit?
(13May,12:40) gaurav_bhumika
Actually,iusedtoworkonTurboc++anditusedtoworkonit.andalsoiamnewtocodeshef.ButYesItseemsstrange,
http://ideone.com/ObhNFA,itsworkingnowbut,timelimitexceed,butimtryingtodevelopbetterlogic.
(13May,00:21) betlista
forinput
1
<<>
yourcodereturns2,butcorrectis0
http://ideone.com/ALp6VO
(13May,01:07) masif
Thanksalot!
(13May,01:08) masif
Hadn'tunderstoodthequestionclearly..
(13May,02:54) betlista
Mineisherehttp://www.codechef.com/viewsolution/3815607
6/17/2014 COMPILER - Editorial - CodeChef Discuss
http://discuss.codechef.com/questions/42551/compiler-editorial 3/4
0
link | awardpoints answered14May,13:38
subham_kumar
61
acceptrate:0%
edited14May,18:13
betlista
11.7k4196186
0
link | awardpoints answered14May,17:47
srinivasam
1
acceptrate:0%
0
link | awardpoints answered11Jun,10:25
grvana
0
acceptrate:0%
0
link | awardpoints answered11Jun,11:26
brobear1995
302
acceptrate:0%
addnewcomment
Cananyonetellwhichcaseiamleaving??HavetriedmanytimesbutcantgetitAccepted.
edit:http://www.codechef.com/viewsolution/3904670
addnewcomment
Pleasegiveatestcasewheremycodefailsforcompilersandparsers[http://www.codechef.com/viewsolution/3876116]theabove
linkisthecodewhereihadwritteninjava
addnewcomment
whyimgettingWAforthis.pleasehelpmewiththisthanksinadvance!!http://www.codechef.com/viewsolution/3900904
addnewcomment
whatdoyoumeanbyadhoc?(oneofprerequisites)
addnewcomment
1 2 next
Youranswer
(14May,18:15) betlista
Yourcodeisnotworkingonideone,canyoufixit?http://ideone.com/1AnFUYIusedyourlastsubmissioninpractice...
(14May,18:11) betlista
Youwaskindoflucky,yourcodeisnotworkingonideoneIhadtochange
Scanners=newScanner(System.in)
Stringstr=s.nextLine()
to
//Scanners=newScanner(System.in)
Stringstr=rea.nextLine()
andthecodereturns040forinputfromproblemstatementhttp://ideone.com/UyDMNu,canyouforkitandfixitonideone?
(11Jun,10:47) rishabh1994
trythistestcase<<>.Theanswershouldbe0,buturcodegives2.
(11Jun,11:52) grvana
@rishabwhysocoz<<>lasttwobracketsarematchingwhichisthecasewiththeofficialtestcaseof<>>>whichgives2asoutput.plzclarify
it:(
(11Jun,12:29) betlista
youshouldoutputthelengthofthelongestprefix
http://en.wikipedia.org/wiki/Substring#Prefix
(yesterday) grvana
thankugotit:P
6/17/2014 COMPILER - Editorial - CodeChef Discuss
http://discuss.codechef.com/questions/42551/compiler-editorial 4/4
PostYourAnswer
[hidepreview] communitywiki
AboutCodeChef AboutDirecti CEO'sCorner
CodeChefCampusChapters CodeChefForSchools ContactUs
2009,DirectiGroup.AllRightsReserved.
PoweredbyOSQA

You might also like