i want the code sir had written in video.
Can i get the code sir 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
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.
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.
Hello @anubhavb11,
Mistake:
-
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];
} -
Size of your array.
Problem:
Not meeting the constraint -
You are passing the wrong variable to the function
Solution:
You have to pass the xor i.e. ans instead of n. -
Wrong order of printing output
Corrected Code:
Hope, this would help.
Give a like if you are satisfied.
Hello @anubhavb11,
No, it is not:
I think you are executing the wrong code.
Following is the corrected code:
why my ide show error here
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.
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.