WA - Variation (ZCO15002)

Problem : Variation
My code : https://pastebin.com/0ExKhXDG

Can someone find the error in my code please?

I don’t think reverse(a,a+n) built in function exist and moreover u didn’t initialize count to 0.Hope this helps and moreover u can try to optimize ur solution.

reverse(a,a+n) exists, GeeksForGeeks has it. Both of what you said does not help.

1 Like

He’s wrong about std::reverse, but he’s absolutely right about count - you should initialise it to 0.

Even after initialising it to zero, I am getting WA… :thinking:

Your code fails on the sample testcase.

Yes, that is why I am asking what is the wrong logic in my code and how to correct it?

 for(int j = i; 

This should probably be i + 1, but that doesn’t fix it. Investigating further …


Ah - the line mentioned contains multiple errors: j should be initialised to i + 1, and you should be incrementing j, not i, and testing whether j < n, not i < n :slight_smile: i.e.

for(int j = i + 1; j<N; j++){
1 Like

So what should I do to the above loop

for (int i=0; i<N; i++){

because you are saying we should not have i<n and not increment i

That line’s fine - everything I said was about the for (int j =i; line.

Oh okay, thanks a lot, it worked. :grinning:

1 Like