 What's up guys, my name is Michael and welcome to my YouTube channel today. We're gonna do another leak code challenge called unique email addresses so basically when you're given an email address you have the first part which is Whatever is before the ad symbol and that's the local name And then you have whatever's after the ad symbol and then your dot-com and that's the domain name so Besides those characters emails can contain dot and pluses. So if you add dots between the local names It's the same address as a local name. So Alice dot Z. It's The same as Alice Z Okay, at leco.com at leco.com they go to the same email address and If you have a plus in a local name everything after the first plus sign Will be ignored. Okay, so m.y plus name right Everything after the plus sign this plus name from the local name will be removed and ignored and Because there's a dot here It's the same thing as the dot being ignored So it's my at email.com. Okay So the reason why is because the plus ignores everything after the plus so this is ignored Up to the at sign by the way up to that sign and then the dots Are ignored. Okay, so the dots are ignored and the plus sign is ignored. Okay So given a list of the emails We send one email to each address in the list how many different addresses can actually receive the emails So how many different emails can you actually have given the list of emails? so You're just returning the number of unique emails. Okay, and yeah That's basically it Yeah So I'm gonna explain the solution. I'm kind of really to I'm really really Sick right now. So I'm gonna explain the solution right now on what I did to get this solution, okay, so let me just get my submission and Explain it right now Actually, I should get my latest submission Okay, so Let me just copy this So what data structure actually is the best for getting unique? Items it's a set the reason why a set is best for unique items is because Sets don't allow duplicates. So you should use the data structure set So what I did was I had a set called that it has a type string And it has it's called unique Okay, so what I do first I Loop through all the emails in this Array of a vector of emails. Okay, and what I do first first. I got each email. Okay, this is just for readability Okay, I've had a string and I said I'm gonna get each email. Okay I'm going to find every position That has the at symbol Okay reason why is because I want to Extract the local name and the domain name. So I want to extract So every time I find this at symbol, I want to extract this local name Alice and Lee code com. Okay Once I get the Once I find the position of the at symbol I substring a Substring from zero to the position Which gets me the local name here and then I substring from after the position After the position gets me the donate name. So in this case after the position would get me Lee code com. Okay, and The local name would be Alice. So that's what the substring does Okay So now I have the local name and other don't name domain name. I am going to essentially find a plus sign, okay? and The reason why I'm going to find the plus sign is because I want to ignore everything after the plus sign In my local name Okay, so I find the position of a plus sign based on the local name And I check if it's not equal to the end position. This is what the string is. So if it's not equal to the end Okay, that means that I found a plus sign Once I find a plus sign, I am going to substring from zero to that position This is going to remove everything after the plus sign. So in this case let's say I have my m dot y plus name at g email com So the first part of the code got me the local name. So that's going to get me m dot y plus name Right because I substring from zero to the position of that symbol Okay, so that just extracts this part once I got this part. I Check if there's a plus sign. So in this case, there is a plus sign and I want to ignore everything after the plus first plus sign. Okay, so because I found I Do dot find which returns a position of plus sign if it's not equal to the end position That means I found it. I found a plus sign. So I substring from zero to that position. So zero to the plus sign Zero the plus sign would get me this m dot y Okay, so that ignores everything after the plus sign plus name that ignores this part that ignores plus name, okay Now once I have this M dot y And I ignored everything after the plus sign plus name I'm going to erase Everything that has a dot reason why is because I want to ignore all the dots. Okay That's what The periods the dots between the characters. We're supposed to ignore those they're gonna be forward to the same address so I do a call the erase function and then I essentially pass in the Beginning position and ending position of the name and I'm going to remove every Dot okay, and that's what this part is This is shut this essentially removes every dot. Okay All right, and then I'm going to essentially erase erase every dot Use the local name from local name. Okay from local name to the end So this just removes the first dot I think Essentially, this is just This is just removes the dot where this is like a function remove And I'm going to pass that in here and remove all the dots. Okay Once I remove all the dots That will get me my in this case because we are we we Removed all the dots here. So that got me my right and then I concatenate it with the domain name the domain name was everything after the position which was This the at email.com so I concatenate those both and then I insert it into my set So once I insert into the set this guarantees. There's no duplicates and Then this function this for loop basically ends and then I return the size That's essentially how you would do this question Okay, we're a removing ignoring everything after the We we first extract the local name and the domain name everything from that the at symbol then we basically substring everything from zero up to the First plus sign to ignore everything after the plus sign then we remove all the dots all the periods From our local name and then we insert it back into the set using local name plus domain name And that's basically how you do this Do this solution? It might have taken you a while to figure it out, but it's not If you if you've done some if you like focused a lot and try to your best You could definitely figure this out Anyway, Raycom subscribe. I hope you guys enjoyed this video. Check you guys later