Problem : Variation
My code : https://pastebin.com/0ExKhXDG
Can someone find the error in my code please?
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.
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…
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 …
Edit:
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
i.e.
for(int j = i + 1; j<N; j++){
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.