Тёмный

How To Solve Lonely Integer HackerRank Problem [Using Bit Manipulation] | XOR Trick 

JAVAAID - Coding Interview Preparation
Подписаться 38 тыс.
Просмотров 12 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 31   
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
Hello Coding Lover, I wanted to clarify one thing here- @5:50 I have formed the group of all integers[(1^1)^(2^2)^(3^3)^(4)] in sorted order. It is just to make the calculation easy. But in general, the operating system does not behave like that. It will do xor with the next element and whatever the result comes it will store and do the xor with next element like- 1^2 = 3 then 3^3 =0 0^4=4 4^3=7 7^2=5 5^1=4 I have shown in that way because for human being its the fastest method to tell the answer without much calculation and if you hear before 5:50 it clearly said that we can simplify the expression like this , it means , its just a human way to simplify to get an answer but not the operating system way. If you still have some doubts, let me know in comments.
@jatinbhardwaj9020
@jatinbhardwaj9020 Год назад
Please Bring Next Videos On HackerEarth Coding Problems Soon.
@FracsoMehdi
@FracsoMehdi 9 месяцев назад
Thanks for the video, but here is a more clear explanation for maths nerds (and engineers too) 1- XOR is associative (the missing keyword that should have been added to the video), meaning A^B^C^D is equal to (A^B)^(C^D) 2- XOR is commutative meaning A^B is equal to B^A 3- XOR a number with itself will result in 0 So, by combining these rules, you can calculate the operations in any order, and scramble the numbers as you would like and you'll still get the same results, just like additions: 1+2+3+4 = (1+2)+(3+4) = (1+3)+(2+4) = 4+3+2+1
@pablocorrera5360
@pablocorrera5360 2 месяца назад
thank you so much, you explain the solution so well
@swap2281997
@swap2281997 2 года назад
Thank you so much for this video. This helped me in learning something new today :)
@crappykeys
@crappykeys 5 лет назад
Thanks for explaining! Have a nice day
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
Thanks @Aditya and same to you.
@codingfreek5737
@codingfreek5737 5 лет назад
Nice explanation with XOR technique..!! (Y) make more video on algo problem on hackerrank bro..
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
Sure. there are lots of videos are in a queue. Please stay tunned..!! and don' t forget to subscribe my channel.. :)
@shivkumarpawar323
@shivkumarpawar323 4 года назад
Thanks bro. You are doing great job
@JavaAidTutorials
@JavaAidTutorials 4 года назад
Thanks for the feedback 😊
@MahmoudAli-wh7ht
@MahmoudAli-wh7ht 5 лет назад
Nicely explained thank you
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
Most welcome..
@watchyourstepskid
@watchyourstepskid 5 лет назад
hey! I don't get why 1^2^3^4^3^2^1 = (1^1)^(2^2)^(3^3)^4. Does XOR operation automatically sort my array? Or just found same numbers in my array and return 0?
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
just to show you that all number has pairs except 4, i have mentioned in bracket near by same number. there is no such operation performed like sorting. it performs xor operation which ever comes first and later on return the final result. if all number having even occurrences then it will return zero else that number which is having odd occurrence.
@rishitsheth1
@rishitsheth1 5 лет назад
@@JavaAidTutorials You are wrong bro. xor.pw/# This is how xor is performed. Select decimal. Your program and logic works but that's not how actually the code or xor works.
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
@@rishitsheth1 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
@rishitsheth1 5 лет назад
@@JavaAidTutorials Sure This is what is actually happening in your program. 1^2 = 3 then 3^3 =0 0^4=4 4^3=7 7^2=5 5^1=4 hence, answer is 4. And not 1^1 ^ 2^2 .... That is not the way. You can calculate the xor using the website link convert the input and output values to decimal.
@rishitsheth1
@rishitsheth1 5 лет назад
Just add this line in the for loop to know what is actually happening. System.out.println(result); Thanks.
@minamedhat7115
@minamedhat7115 Год назад
Thank youuuu
@keerthi442
@keerthi442 4 года назад
Plz upload it soon I have interview 😉
@JavaAidTutorials
@JavaAidTutorials 4 года назад
what you want us to upload?? 🤔
@keerthi442
@keerthi442 4 года назад
@@JavaAidTutorials interview preparation kit in hacker rank even more plz
@rishitsheth1
@rishitsheth1 5 лет назад
What is 2^A? or 4^6? Btw, you are doing a great job. Keep it up man.
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
Hi Rishit, I did not get your question 2^A or 4^6? what you are trying to achieve here?
@rishitsheth1
@rishitsheth1 5 лет назад
@@JavaAidTutorials Sure This is what is actually happening in your program. 1^2 = 3 then 3^3 =0 0^4=4 4^3=7 7^2=5 5^1=4 hence, answer is 4. And not 1^1 ^ 2^2 .... That is not the way. You can calculate the xor using the website link i provided, convert the input and output values to decimal first while using that. Thanks, keep doing what you are doing. I appreciate.
@JavaAidTutorials
@JavaAidTutorials 5 лет назад
@@rishitsheth1 No need to add the last line, 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. Once again thanks for pointing out the mistake..keep on doing it.😊
Далее
Lonely Integer Problem - HackerRank | Code Challenge #1
20:24
How To Solve HackerRank Drawing Book Problem
11:00
Просмотров 17 тыс.
The TRIPLE FOLDING phone has a Problem.
12:54
Просмотров 1,9 млн
The size of your variables matters.
11:03
Просмотров 128 тыс.
Diagonal Difference HackerRank Javascript
8:19
Просмотров 9 тыс.
HackerRank Luck Balance Solution Explained - Java
10:59
How to start Competitive Programming? For beginners!
9:43