Java-aid / Hackerrank-Solutions

hackerrank solutions github | hackerrank all solutions | hackerrank solutions for java | hackerrank video tutorial | hackerrank cracking the coding interview solutions | hackerrank data structures | hackerrank solutions algorithms | hackerrank challenge | hackerrank coding challenge | hackerrank algorithms solutions github| hackerrank problem solving | hackerrank programs solutions | JAVAAID |all hackerrank solutions | Coding Interview Preparation
https://www.youtube.com/c/JavaAidTutorials?sub_confirmation=1
MIT License
1.73k stars 861 forks source link

The video Tutorial for Lonely Integer has wrong explanation. Refer http://xor.pw/# for real logic. #5

Closed rishitsheth1 closed 5 years ago

kanahaiya commented 5 years ago

@Rishit Sheth I really appreciate your feedback. But I did not understand clearly what is wrong in my tutorial? Could you please elaborate in details so that I can fix it if some problem exists.

I will just try to explain what I understood from your question- I did not say in my video that XOR works in the same way which I taught, I have just tried to simplify the calculation which can help people to calculate fast instead of doing bitwise xor(one by one). I know XOR works on the bit(zero or one form), before performing any bitwise operator it will convert into the bit and do the operations. Here I assumed that people are familiar with XOR operation and if I right 4^0 it means internally the computer will treat 100 ^ 000=> 100 and give 100 which 4.just to avoid all the steps I taught you all that trick A^0==> A which will help you to answer this quickly instead of converting A into binary and performing XOR operation with 0 then get the final result.

Please, let me know if I answered your question.

rishitsheth1 commented 5 years ago

The last part A^0 and 4^0 = A and 4 respectively is true. But the compiler does not bring together the numbers and do 0. It does step by step process, 1^2=3, then 3^3=0, and the 0^4=4, 4^3=7, 7^2=5 and finally, 5^1=4. Your explanation already created doubts that whether it will sort the array first or not as seen on your video's first comment.

So, my take is just going step by step and explaining what is actually happening would be more helpful. To be honest I did not know anything about xor in program; but after watching your video did try to understand what is actually happening and found the xor website.

Or you can just add a Print Statement in For loop and you would see that what I am telling is what is actually happening. And that's how we get the answer 4. Of course it happens bit by bit by the ultimate answer is NOT calculated by joining two same numbers together but by individual calculations each time with different numbers and getting the result.

kanahaiya commented 5 years ago

No need to add the print statement, I know how it works. but to make other people understand I used a trick and forget to inform that its trick but the computer will not behave in the same way.

It will not sort the numbers before xoring, I showed in this way to just how as a human being you can quickly get the answer instead of doing sequential which can take a lot of time for the human being.

but anyway thanks for your feedback and I really appreciate that this is also a learning for me that I should have mentioned somewhere this in the video that it will not sort the number etc..

Will check if there is some way to add this note will add it for sure.

Post: I will definitely consider your point- "step by step and explaining what is actually happening would be more helpful." or will add a note if I am doing something different.

Once again thanks for pointing out the mistake..keep on doing it.😊

rishitsheth1 commented 5 years ago

Yo; both - your thing and the thing that's happening is probably the best for explanation.

You are really doing a great job. Keep it up man.