 What's up, guys? Mine's Michael and welcome to my YouTube channel. Today, we're gonna do another code forces problem. This is code forces round 606 division one of the problem is called as simple as one and two. So you're given a non-empty string or that consists of some minor substrings, right? That has a lower case line letters, but this guy named polycard doesn't like it. If it only if it contains at least one one or at least one string two. Okay, so I've has one or two. He doesn't like it or if he has both, right? So one two or one, both one two. Okay, as a substring. So in other words, he doesn't like it if the string s has any of the characters are something that equal to one and two. Okay. So for example, these strings one, he doesn't like it because it has a substring one. And on two w doesn't like it because there's a two here. And two one, he doesn't like it because there's a one here and there's a two here if you interpret this way, right? And he doesn't like it because he has one one one two because it has one as a both of ones and twos right has one two one one one two, right? It has at least one of these. So he likes it if the strings are like this like only me the reason why because it doesn't spell one like it just doesn't spell one. Wow, wow. Okay. The reason why because it doesn't spell to like there's no T. W. Oh, right? Ton now, whatever. It has no one ones and twos. Okay. So in this case, if you let's look at this example one two one, right? Um, so if you want you basically he wants us to select a set of indices positions and remove all the letters of these positions. Okay. Excuse me. So, uh, he wants in this case, he wants to select three and six, right? So this industry at three, uh, they're in their indexing at one, right? They're doing one, two, three or five, six. So they want us to remove this index and this index. Okay. We'll be selected and the result is on town. So what is the minimum number of indices or positions that polycarte needs to select to make the string liked? And what are these positions will be? Okay. So there's these test cases and then there's a strings s stuff like that. Okay. So what I'm going to do is, uh, I should tell me a lot of tries to get this right, but, and my solutions, it was still kind of long. So I'm actually going to go over the editorial solution. But anyway, uh, in order to do this, let's go back to the paper because if you draw out all these inputs and output and the corresponding outputs, you actually see the pattern. The problem wants us to basically remove the minimum number of letters to not have the substring one and two, right? So in this case, we saw that from the input statement, there's this one, two, one. So the letter they want us to remove is three and six. So they want us to remove this E, which would get rid of this one and this O, which would get rid of the one here also, but it also gets rid of two. Okay. So basically based on the first input statement, I know that if I want to remove the minimum number of letters to, to not have the string one, two. If I just remove one O, then that's actually the minimum, the minimum number of the letters to remove in this case. Toe one, right? Because the reason why is because that if, if I remove, let's say I remove a T to get rid of this two and an N to get rid of this one. So there's a sub string of one here and there's a sub string of two here. If I remove a T to get rid of this two, that counts as one removal, right? And then I remove an N to get rid of this one sub string here. That counts as another removal. And then if I remove this E, that counts as three removals, right? So that's, that's way more than removing one letter in this case. So in this case, if we see a two own, right? I got a two merge with a one, we should remove an O, okay? Based on the first input statement that I looked at, this would minimize the number of letters I have to remove. Then after looking downwards, as you can see here, this test case, there's nothing to remove, right? So they put zero and then they print out an empty string for this test case. The rest of the test cases, this test case and this test case, they just removed the first letter and that's okay. Let's, let's go to an interesting one, like this one. Two O, okay? Well, if I were to remove the last letter to get rid of this two, I still have a two in the end, right? If I get rid of this, I still have a two. So that, that doesn't work. So you can't just remove the last letter whenever you see a two. If I want to get rid of twos for any substring that has two, right? I can't just remove the last letter because then I still, I would still get a two here. I would still have two like that. One, two, three, four. Yeah, I would still have this, right? Two O, O, O. So that wouldn't, that wouldn't work. And if I look at this, let's say I wanted, let's say I look at the next test case, this test case. Two TTTTWO, right? So they picked an O to remove, which makes sense, right? The last O, but picking the O to remove doesn't work in this case, right? In the case that we just said above because of an actual O would still have two there. So let's look at this test case. If I were to pick the T to remove, like let's say, let's say I saw a two. So this test case has a two string, right? The string that has a substring two. That's how I picked this to remove this T. Well, I would still have a two, a substring of two. Like it would still have TTTWO and this is still has a substring two, right? So in this case, the best case to remove is actually the middle. Middle string, which is W. So whenever I see a two, it's actually best to remove a W because then I know that I definitely know that there's not going to be like a T's in front of it or O's in the behind it that would actually affect it, right? Because if I see a two, if I remove a W, that would completely get rid of any of these cases of having another substring two at the leftover, right? Okay, so, and let's go to one. Just like in a O, O, O, N, E. Let's look at this test case. They removed the test case, the letter N, right? They removed the letter N. Well, in this case, that makes sense, right? It makes sense to remove the letter N because then you won't have the substring one, right? So, but let's say, whenever I see a one, I remove a letter O. Well, that wouldn't work, right? Because if I have another O's in front of it, I would still have one later on. If I remove an O in front of it, like if I remove this O, I would still have one, right? I would still have this one, this one, which still has a substring, so that's not good. And in this case, one E, if I see a one and I see an, and I remove the E, like the last letter E, that doesn't work either. So, because I would still have one E, right? I would still have one E, like that. So that's not a good idea either. So, whenever I see a one or two, basically, I'm going to remove the middle letter, okay? So, if I see a one, I'm going to remove an N and that would completely get rid of my, get rid of my, the, get rid of the substring one, okay? And if I see a two and get rid of the W, that will completely get rid of the substring two, okay? So, that's what we saw based on these test cases, okay? So, if I see a one, I'm going to remove an N, if I see a two, I'm going to remove a W. And then, if I see a T, W, O, and E, I'm going to remove the O, okay? And insert that into whatever vector that I need to return to, okay? So, but, okay, so, first, I have to check, but let's see the, the actual scenarios to check first. So, first, I have to check if there's a T two, two own, right? Then remove the O to not double count it, right? To not double count the number of letters to remove. So, I would just remove this, the O. Then I would check T, now I would check the string to substring two and then remove a W. And then I would check one and remove an N. So, that's basically the code, okay? That's basically the algorithm. We're going to check two and then remove the O. Then we're going to check T, W, O, and then remove the W. And then we're going to check the string one and remove the one, okay? And now I'm going to go to the code and then code this up for you guys. Alright guys, so here I have a visual studio up and I just read in the test cases, number of test cases, T. And I did wild T minus minus to read in the, each test case. And then I read in the string S, I created string S and I read in the string S. So, they start, there's as four string T for every T that's in this array of a set of T, W, own. And then two and then one. So, they did it like this way. So, they're going to go through every string in this set, tone two and then one, to check every single occurrences of each of these strings, okay? So, just like the order that we set in the, when I showed you guys, okay? And then what did they do? Okay, so then they created a position size T position equals zero. So, starting position to search at. And then they're going to search S dot find T with the position. And they're going to keep on doing it until it's not equal to N position, which is negative one, I believe. Okay, so they're going to do this. They're going to keep doing this. What's my problem? Oh yeah, oh okay. So, they did position is equal to this. Position equals a find this size under square T. Okay, well I can't do this for some reason, so I'm going to make it an int. Why can't I do this? Let's see, why can't I? Okay, I'm going to put parentheses to see if, okay, so that works. Why can't I do this for? You can't do it in this. Okay, fine, fine, fine, fine. I'll create a pause out here then. I'll do a while loop. Okay, this is different from the other tutorial now. So, bear with me. Why can't I do this? Why can't I do this? I actually don't know why I can't do this. Okay, now I can do it. Okay, well that's really weird. Okay, so while, so what is this doing? I'm going to find the occurrence of the string. So, okay, so let me step back a bit. Okay, so what I'm going to do here is for every string that's in T, every T that's in this set tone two and one, I'm going to find the string tone and then two and then one. Okay, so I'm going to find the occurrences of each of these strings. Okay, so that's what I'm doing in this for loop. So, in this position, I create a position index to tell me the index of where the next occurrence is, right? So, I'm going to find the string, the first string tone using s.find and that's going to give me the first occurrence of where tone appears in the string. So, that's what this does. And then after it finds that, I'm going to set my position to equal that in the next iteration. So then I could, I don't have to put this in the end, right? Next iteration, so I could do pause equals that, okay, right? And I'm going to keep doing this until I don't equal to negative one. So, end pause is what it returns if find returns negative one, because that means that there's no more occurrences of this string tone, tone, right? And then after this is done, I'm going to find two and then I'm going to find one, okay? All right, then what do they do? Okay, okay, so then what they did was they set s at position plus t dot size over two. And they're going to set this equal to x to remove it, okay? So, they're going to remove the value of this, okay? So, what does this do? This is a hacky way to do it. So, I'm going to find the position of this whatever starting position it was. So, if I find a position of tone, tone, right? Tone, whenever I find the position of tone, right? I'm going to find that position in the string, right, that I'm searching for. Then what I'm going to do is I'm going to take the size of tone divided by two. So, then this gets the middle one, the size of the middle one, which is like, I don't know, three. So, that gives me the offset to add to my current position, right? And then I could just remove the middle to equal x, okay? So, this is just a hacky way of doing it, okay? So, this basically just saying is that I'm going to remove every single middle value, okay, of each of these strings that occur inside the large string, okay? That's what this is doing. So, right, and then what, okay, what else do they do? Okay, then they're going to do a pushback. So, now we actually have to add it to our set. So, I'm going to do a quickly create a vector int r, okay? Then I'm going to do r.pushback and I'm going to pushback this position. So, this is going to tell me the actual, this is the actual position of where it is in the actual string, okay, the middle position. So, this is the middle position of where it's at, okay? So, I'm going to pushback the middle position and then, what does it do? Yeah, then that's it, okay. Then at the end, I have to print out the size of how many that I'm removing and then I have to basically print every integer that's in my vector, okay? Yeah, I actually have to print out whatever integer plus one because they want to index by one. So, yeah. And this ideally should work. Whoop it does. Just copy, go to this one and then submit the code. Okay, well, it stopped at running out of test one so that means something's an issue here. What is my problem? What's my problem? Ideally, this should work. Hmm, oh no, wait, it didn't stop. Okay, it got eight seed. Okay, it just took a while to load, but yeah. Yeah, so that's how you do this problem. I just quickly explain it to you guys here. I'm trying to cut the video length of these bits to be shorter because I don't feel like explaining 30 minutes of you guys and I feel like 30 minutes of explanation is way too long. But yeah, that's how you do this problem. Raycom, subscribe. Let me know if you guys want me to do the next problem of 629. Let me do that and yeah, Raycom, subscribe. I'll see you guys later. Peace.