Can i get the code sir written in video

i want the code sir had written in video.

Hello @anubhavb11,

I can share the code with you and that’s not even a problem:

But, why don’t you code it yourself?

When you would write yourself, you would get to know what you have understood and what are areas you have to work upon.

Hope, this would help[.
Give a like if you are satisfied.

how that part is giving right position it can only give 0th postion else it will stuck in infinite loop because we are not updating temp

code- https://ide.codingblocks.com/s/234134
i tried to code my own but it is not working for 4

Hello @anubhavb11,

Yes, you are correct, there is a mistake there.
Correct code:

what is problem in my code could you please tell that

Hello @anubhavb11,

Why are you left shifting the ans by i bit positions?
Mistake:
ans = ans>>i;
Solution:
ans = ans>>1;
Explanation:
You have left shift the number by 1 bit position in each iteration.

Hope, it is clear.

1 Like

giving wrong ans - full code

Hello @anubhavb11,

No, it’s not.

It is passing both the test cases for me.

Try to submit it again.

not your code i am talking about my code
code- https://ide.codingblocks.com/s/234197

Hello @anubhavb11,

Mistake:

  1. Wrong way of computing xor:
    for(int i=0;i<n-1;i++){
    ans = arr[i]^ arr[i+1];
    }

    Correction:
    for(int i=0;i<=n-1;i++){
    ans = ans^ arr[i+1];
    }

  2. Size of your array.
    Problem:
    Not meeting the constraint

  3. You are passing the wrong variable to the function
    Solution:
    You have to pass the xor i.e. ans instead of n.

  4. Wrong order of printing output

Corrected Code:

Hope, this would help.
Give a like if you are satisfied.

but still it is showing wrong output

Hello @anubhavb11,

No, it is not:

I think you are executing the wrong code.
Following is the corrected code:

1 Like

why my ide show error here
image

visual studio
compiler migw64
errror- expression must have a constant value – the value of variable “n” (declared at line 21) cannot be used as a constant

Hello @anubhavb11,

Solution:
Use a constant value for the array size.
What should be the size?
Read the question. Constraint is mentioned and that is the required size.

Reason:
The standard requires the array length to be a value that is computable at compile time so that the compiler is able to allocate enough space on the stack. In your case, you are trying to set the array length to a value that is unknown at compile time. Yes, i know that it seems obvious that it should be known to the compiler, but this is not the case here. The compiler cannot make any assumptions about the contents of non-constant variables.
some compilers will actually allow you to pull this off. IIRC, g++ has this feature. However, never use it because your code will become un-portable across compilers.

Hope, this would help.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.