 What's up guys, my is Michael and welcome to my YouTube channel. Today we're going to do a leak code 30 day leak code challenge. Pretty much after every single one day, I'm going to go over the leak code solution with you guys and explain how to do it. Okay, so the first The code problem was single number, which is given a non empty array of integers. Every element appears twice except for one. So we have to find that single one. Okay, so main issue is trying to do it without extra memory and your algorithm should have linear time complexity. So based on this first input case two, two, one, it should output one. The reason why is because one is the only number that is not repeated twice. Okay, and the same goes for this one because input four one, two, one, two, the only number that's not repeated twice is four. So that's why the Answer is four. So originally I did this by using a hash map, which I just added the number of occurrences of every single number, and then I added by one, then I looped through again through the hash map and I checked if I find the number of occurrences equal to one, then I return it, right, I returned the number that had the first number of occurrences is equal to one. But apparently you could actually do this really fast, differently. And it actually involves the ability of It's operated called x or okay. So first I'm going to do is I'm going to create a number called some, I don't know, not some I don't know to return create number to return I'm going to set to zero. Okay, and what am I Oh, whoops, my bad. So what am I going to do I'm going to go through every single number of value inside my nums. What am I going to do I'm going to keep saving it by accident. I'm going to x or my to return with my value of value. Then after that, I'm going to return to return. And what does this code do? Well, let's see first, if it actually gets past it, because yeah, okay, so I got accepted. Okay, so what is exactly does this code do? Well, you have to understand what X or the X or operator does. So this is the operator X or. So what exactly does X or operator to do. So for every single bit in X or the ones that are like, let's see how do I explain it. I have to explain it on paper to explain it to you guys, but so I'll explain X or in a different video, pretty much like a way more in depth of X or, but pretty much in this case, where you have two numbers right in a not two numbers. When you have value, every element appears twice except for one right. So we know that when you whenever you X or two numbers, and they're exactly the same number, it's going to amount to zero. It's going to equal to zero in the end. So if I X or two and two, it will become zero in the end. Okay. Now the thing is, is that if you X or any number, let's say two with zero, you get two. Okay, you get the exact same number. If you X or any number with zero, you get the exact same number. So what happens when I X or all the numbers in this array to two one, pretty much any number that got duplicated to two, right? It'll be if I X or two and two, it'll become zero. Right. And then the remaining number is going to be by itself. So then when I X or zero with the remaining number that didn't get duplicated, it'll get the same value itself. Right. It'll get the same value one. So that that's basically how the X or operator works in this solution. Pretty much if you X or anything with itself, right, you'll get zero. And then if you X or zero with that number, I'll, it'll get the same number again. So pretty much if I X or all the numbers here, anything that was duplicated will become zero and then I'll be have the leftover number and then I'll X or zero with that number. And then that is just going to repeat that same number. It's going to equal to the same number, the left, the same number as the leftover number pretty much. So whenever you X or all the values here, let's say in this value four, one, two, one, two, these ones, one, one would become zero, right? And when I X or one, one, and I'll become zero, and then the bits of this number two and two, they'll become zero. And then I'll be left with zero, right? After all these values got X sort, I'll be left with zero. And then I know that this number four, because there's no another number four, it's not going to be zero, right? It's left over. This number four is left over. So then when I X or my leftover numbers of zero of after X or all these zero with four, it'll become four, right? Because any number that's X or with zero is going to become itself. So that's basically how this X or number problem works in this problem statement here pretty much is pretty much just explaining how to use X or operator. So yeah, that's how you do this solution of simple number in a lee code. The first challenge of single number. I hope you guys understand the solution. I hope I explained it correctly pretty much anytime you have a duplicate number and you X or it with itself, right? It'll become zero. And then because we know that all the every element appears twice except for one value, right? That leftover value is not going to have another value. It's not going to be duplicated. So then it'll become zero and then like everything else will become zero and then except for that one value. And when you X or that number with zero, that leftover one value with zero, it'll get itself. So that's how this solution works. Ray com subscribe. I hope you guys enjoy this video and I'll check you guys later.