Later after the contest when i tried to debug my code i found out it is getting accepted if i am using ‘vector’ and failing while using ‘array’, rest everything is exactly same. Can someone please help me why is this so ? Am i doing something wrong here ?
Your (input) array solution is not working because you have not initialised the array, Though it should have not been a problem as every element till N is given a value (by input), unless there is some problem with test cases. I have tried with submitting without initialisation for both array and vector, and it doesn’t work, and it works after initializing using any value.
@keshav_7@sunil5798 That is strange. Initialisation of array should not mandatory if we have input size.
You rightly said there could be a problem with test case.
One case scenario i can think of - The number of elements of array in the inputs is not equal to N.
Eg.) 5 2
2 3 4 5
Original array - “2 1 7 1 0” (for vector) and “2 1 7 1 random” ( for uninitialized array)
Correct output - 2
With Vector Solution - 5th element will be 0. So, Output = 2.
With Array Solution - 5th element can be any random number. As, array is not initialised. If original array’s 5th element ( = 5 XOR random number ) has 2nd set bit. Output = 3. Hence, a wrong answer.