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

preview_player
Показать описание
Lonely integer hackerrank problem can be solved easily by using bit manipulation technique. The complexity of lonely integer hackerrank solution is O (n). This hackerrank problem is a part of Practice | Algorithms | Bit Manipulation| Lonely integer hackerrank challenge.

This video explains how to solve lonely integer hackerrank problem in java. Here I have explained the algorithm to solve hackerrank lonely integer problem separately and then implemented the same algorithm using java.

For simplicity, I have divided this hackerrank tutorial into 3 parts.
1) Understanding the problem statement.
2) Building the logic to solve the problem.
3) Coding the logic using java (you can use your own preferred programming language).

✚ Join our community ►

📖 Resources ►

✅ Recommended playlists ►

👋 Let’s Connect ►

#JAVAAID #HackerRankSolutions #HackerRankTutorials #HackerRank #JavaAidTutorials #Programming #DataStructures #algorithms #coding #competitiveprogramming #JavaAidTutorials #Java #codinginterview #problemsolving #KanahaiyaGupta #hackerrankchallenges #bit #bitmanipulation #lonelyinteger #xor
Рекомендации по теме
Комментарии
Автор

Hello Coding Lover,
I wanted to clarify one thing here-
@5:50 I have formed the group of all 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.

JavaAidTutorials
Автор

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

FracsoMehdi
Автор

Thank you so much for this video. This helped me in learning something new today :) <3 Please keep uploading stuffs like these.

swap
Автор

Thanks for explaining! Have a nice day

crappykeys
Автор

Nice explanation with XOR technique..!! (Y)
make more video on algo problem on hackerrank bro..

codingfreek
Автор

What is 2^A? or 4^6? Btw, you are doing a great job. Keep it up man.

rishitsheth
Автор

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?

watchyourstepskid