 What's up guys my name is Michael and welcome to my YouTube channel today We're gonna do another leco challenge called subdomain visit count. So a website domain like discussed leco.com Consist of various subdomains the top one we have comm the next level We have leco comm the lowest levels discussed dot leco comm. So what they're talking about is every time you have a dot Top level you have discuss dot leco comm so you have every time you have a dot you have a Have one a visit of one domain. There's a parent domain and then the subset domain So like discuss dot leco comm since there's a dot here after discuss the first one is the first Domain then we have Leco comm Has a another domain and then we have comm as a last domain. Okay, so that's what they're saying here Now we call a count pair domain to be a count representing the number of visits the domain received followed by space followed by the address So an example of count pair domain might be 9001 discuss dot leco comm So you're given a this is basically saying the count the number of visits this domain received so to 9001 be the number of Visits the domain discuss dot leco comm received, okay uh Yeah But it's also including the sub domain is also so like leco comm and then Comm itself. Okay, so that's why in this case 9001 discuss dot leco comm the output They have 9001 distributed across the first domain domain Then it each individual sub domain like leco comm and then comm Okay, so that's nine thousand discuss dot leco comm nine thousand leco comm nine thousand comm So we only have one website domain discuss dot leco comm as discussed above but the sub domains are also visited so they all have They all have each visited 9001 times. Okay So essentially we're just counting we're gonna distribute the count to Each of the domains, okay, the don't google dot mail calm Mail calm and calm and we're gonna do that to distribute 50 to yahoo calm and then calm distribute one to Intel dot mail calm mail calm and then calm and then distribute Five to winky dot or winky dot org and then org, okay So that's why this output the reason why it has this is because they distributed the number to each of the domains and then When they distribute they're also adding the count to it so because nine nine hundred was distributed to calm as well. It's nine hundred plus 50 which was distributed to calm so nine hundred fifty plus One which is distributed to calm also. So that's why it's nine fifty one calm over in this case Okay, so that's the reason why Some of these were added so the domains that were added had a Visited them again. The number was added on to it So I'm gonna explain my solution on how I got this Solution so what I did was I mapped every Every domain to the number of occurrences that that showed up To each domain, okay So I'm at the string and the number of currencies for the for each domain for each pair so we're given the remember we're given a a list of strings and the list of strings are In this case the list of strings nine nine nine hundred Google dot mail dot com Fifty yahoo dot com in each of these strings We have a number representing the number of times this domain has been visited right a space and then The rest of the main domain. Okay, so that that's just what each string represents For this list of strings that were given So what I did was I went through every single domain in This list of domains. Okay, so this it's gonna go through every single Value it like nine hundred Google dot mail dot com 50 yahoo dot com one Intel dot mail dot com five wiki dot work So it's gonna go through every single value in these input array So I create a variable just to store each value each value for each domain and each value of the array So what I did was I found first found the string of a space the position of the space. Okay, so I did each value That I find space reason why because I need to find this space The space of each Each every time there's a space We know that there was a number before it and we know that there's a domain after it Okay, so then then I could separate the Number and the rest of the domain actual domain name. So here. That's what I did here so I substring this substring basically goes from the space the position of the space that I found using not fine and I'm going to subtract by the starting position Which is zero and then adding one because that's where you how you're supposed to do it because we're not including the space by the way, we're substringing and I'm starting from position zero. So this is the length that it that We are substringing from zero. So in that case In this case zero one two three it would do three minus zero plus one so four So we're going to substring four positions from position zero. So it does that. Okay, so that's the number Once I get the number I'm going to s toy it right after I substring from each Substring from zero to the space position, right? I'm going to s toy it and this converts it to a number to enter your number Okay, then I get the rest of the value String rest. This is substringing from the space and onwards. So that gets you The rest of the domain path for every other value. So like Google dot mail dot com yahoo dot com Intel dot mail dot com Stuff like that Yeah, Intel dot mail dot com we get we could artwork. So that's what this the rest of the rest each value does. Okay, then What I'm going to do is That every time we see a dot I'm going to find a dot. Okay, so that's what I'm doing. I'm going to find a dot Reason why I'm going to find a dot is that for every time we see a dot that means we're at a sub domain Okay, so that means that we're going to add Add the we're going to add the number of occurrences of number To that sub domain to rest rest of the value So rest is the rest of the is the domain name. Okay in my case I should put a domain name, but rest is the rest of the values for the domain name here like Google dot mail dot com So what this does is it finds the period so it's going to find this period This period, okay So while this period is not the position of this period is not equal to the end of the string. That's what this is doing This end of the essentially I'm going to occurrences of What I already stored in the map at the domain Added add up the number. That's what I'm doing. Okay So what this is doing is it's gonna say, okay in my map Google dot mail dot com Is going to have the number of currencies is going to be nine hundred for Google dot mail dot com Okay, and I'm gonna store that in my map Okay, once I find the next Dot it's gonna be this dot right I Substring from the rest of the dot so mail dot com Okay, so in this case Let's go back to the previous position what I was doing So right after I got Google dot mail dot com right Google dot mail dot com I get I increased my currents plus occurrences so my recurrence was a current my Current right was the The position of the dot I increased that so now it's going to be the position of M That's what this is doing and I'm going to substring from M. So that's going to take get rid of all the All the values from here Google dot Google dot it's gonna get rid of this So then that means my the my rest of my string is going to be mail dot com Then I set current to find the next dot after that Okay, so since My current is going to point to this dot after that but my rest which is my String that I'm setting for each domain is going to be mail dot com Okay, then I'm going to add data at rest plus equal number. So that's going to distribute 900 to mail dot com and Then I substring from the dot of this dot, which is going to get me Everything after the dot if I substring this plus plus current and that's going to get me calm Right, that's going to get me calm then after that I'm going to add nine After that it's going to try to find the next dot which is going to be the end of the string But before it does that I'm going to add Data at rest plus equal to number Oh, yeah. Yeah, actually Because the current equals to rest dot find it's going to finish this Dot because it's going to be the end of the end of the string. It can't find any more dots Okay, that's what this is doing because it can't find any more dots It's going to be done and then before I end it. I add the last data at rest, which is the dot com plus equals to whatever my To whatever my number was before so the my number of occurrences 900 is going to get added to the occurrences of Com of com in my map and I'm doing that for all these values 900 google dot mail dot com 50 yahoo dot com one intel dot mail dot com five wiki dot org And that's what this loop is doing and after this loop is finished I'm going to have the number of occurrences for each Valley values distributed over Each domain and sub domain after each dot So after that I have a vector called to return to return. I'm going to basically just Go through every occurrences and just Concatenate the number of occurrences for that whatever was to my element of my map and that's what I do here So 900 901 and mail dot com That's just like storing the that's just saying the output 901 space mail dot com mail dot com is the every time and for The strings for all the subdomains and the domains So I'm in this this string is basically just concatenating the number of occurrences To its sub domain or domain name and then I add that to my array that I'm returning then I return and after this for every value in my map None of the occurrences that occurred and my map once that's done. I'm going to return my array To return and that's basically how you would do it the solution was Basically the same Hash map and that they did they did what I did essentially they use the hash map and yeah, that that's that's exactly what I did So yeah, that's my solution rate com subscribe. I hope you guys that like this video and check you out