BESTBATS:Getting wrong ans

sumone can please tell what is the mistake in following code…i am getting wrong answer
http://www.codechef.com/viewsolution/2187870

2 Likes

but can you please figure out what is the mistake in my code.It is working fine with sample test cases but still giving wrong answer.Or please provide me some tricky cases.

your updated code:http://ideone.com/nA8H0g (AC)
bug was on line no 32…
in the condition (a[m+1]==x)&&(m!=11)
the first condition goes out of bound thus resulting a WA.
so the condition should be reframed as (m<11)&&(a[m+1]==x)
so that the second is not evaluated for m==11.Hope it helps…:smiley:

2 Likes

but the code link which you mentioned above shows : (m!=10)&&(a[m+1]==x …which is working…can you please explain the logic behind this…as (m<11) is not working

oops…got it :smiley:

1 Like

oops…got it :smiley:

i was looking at the same thing…but i was putting (a[m+1]==x)&&(m<11) and was getting a WA…good1 rahul…:slight_smile: