Can someone please help me figure out where my solution for Guddu and his Mother(KS1) fails?

Out of the total 8 subtasks my solution gives AC for 4 and WA for the rest of the 4.Please help me figure out an example test case where my solution fails.
Link to my solution:

Thank You

Odd - I’ve tried 1000’s of random and constrained-random testcases, and can’t get it to fail. I can’t see any signs of overflow.

I couldn’t get it to run on my laptop without increasing the stack size, and yours is fairly stack-hungry, but I’d expect this to cause a RTE rather than a WA, though a WA is certainly possible (Undefined Behaviour is Undefined Behaviour …).

Maybe try changing some of your large arrays into vectors?

I am also facing this issue. My solution passed the four subtasks but for the final 4, it failed.
Seems like there is an overflow while calculating the xor prefix. Can someone help?

Yours is much easier to diagnose, and it is indeed an overflow - try it with a testcase consisting of 100’000 “1”'s :slight_smile:


At the very least, one problem is

int count=0;



The multiplications in

count+=(i*vec[i]- (len-i-1)*vec[i] -(len-i-1));

also look like they could exceed the range of an int.