 What's up guys Mike the Coda here today? We are going to go over the contest. It just ended Seven minutes ago. So yeah, let's just go over the first problem I'll just go over the problems I solved and there'll be like two different videos. All right I only solved two problems this contest normally I could so like I'll try to solve three next time But like I just couldn't the second problem just took a long time for me to solve Yeah, I'll get faster at this though All right, the first problem is calculate digits sum of a string So you're given a string s that contains digits and then an integer k so What we're trying to do is we're gonna like split it into like consecutive groups of size k and so on and so forth if it's smaller than k then we stop okay, so like if So let's say we had let's just go over the example So here we have oh my gosh Yeah, so here we have one one You know, I'll just copy this. I'm not I'm not typing this out. This is like a panda, but hey, so let's just copy this Why is this not? Come on Come on Okay, okay. So yeah, so so we have in the example. We have this right one one one one two two two three So they want to split s into like Consecutive groups of size k. So in the first example, it's like three. So we're gonna split this into three. So oh My gosh, so there's here, right size three. So one on one is one size One one one two is another size Two two two two is another size of three Then two three. We don't have any more sizes, right? It's smaller than three. So it's just two three and then For each group, we're gonna just sum all the digits. So This this group of one plus one plus one would be three This group of one plus one plus two would be four two plus two plus two would be six and Two plus three would be five. Okay, and then they want us to Merge these together to form a new string. So then three four six five would be another string. So this would become Three four six five, right? And we just repeat this. Okay Keep going do keep doing this until we get Until our length of our s is like less than or equal to k So in our case, we're just gonna keep doing this again until our length is less than or equal to three So we have three four six and five. So let's just split this by three again. So then we get 13 right three plus four plus six would be 13 and then we have five and Then that becomes our new string. So we have one three five and then because it's Size of three, okay? We just ended there. So we output one three five. So how do you do this problem? the simple gist of it is like you start at zero and We're just gonna like substring Of size K every time and then we're gonna like increment our index by K. So Here we started zero and we're gonna substring to like three Three digits to the right. So then we have one on one and then we're if we start at our index I equals to zero We're gonna add by case when Zero plus three would be here, right? Would be here at this index. So this would be three and Then we plus three again would be like six here and plus three again would be Nine here, right so like just each every time we're just gonna keep like substringing of size K So it'd be three and then we just add by three to the index to go to the next Number to substring by and we keep doing that then every time we substring We're just gonna sum of all the digits So to do that, you just convert it into like the equivalent number So like create like a new variable and then just like add up the digits So what I do here is I just like loop through like each of these individual strings So we have one on one one and then I just loop through and convert each character to like its corresponding digit So one would become one and I just add up all the digits one plus one plus one which gives me three and then I also have like another string that I build up on the new string So that'll be and in the end We append each of these the sums of each of these The three four six five into a new string and we set that equal to our String s is gonna equal to that and we're gonna just keep looping through it Over and over again until we get s's length is less than or equal to K Okay So yeah, that's all we have to do. So that's basically just the algorithm. I'll show you what I did This one actually took me like a few minutes Surprisingly a seed in one go Let me just show you guys the code now because This algo is not that hard Where did I with my submissions? Oh, this one. Yeah, okay, so Yeah, so while s dot size is greater than K, this is the condition that we're gonna keep Do going over and over again? So we're gonna just keep Keep doing this algorithm is splitting between size K's over and over again until our our string is Lesson or equal to K, right? So We're gonna repeat this so we have this while loop s dot size is greater than K We're gonna have a new string that we're gonna build up I call it a new string because it's a new string and then I just have a for loop This for loop is just gonna go through every substring of size K so This is gonna go from here Subtring this and it's gonna subtracting this and it's gonna subtracting this and this Okay, so I add by K every time So yeah, so this I plus equals a K every time Yeah, and then here is a substring string V is it gonna equal to s dot substring I K in C plus plus the The first value of substring is like you're starting index, but the second the second like Input that you're putting the substring is like the length of the characters that you're going to so that's what I like about C Plus plus because in this case I just have to substring from like Start from I zero and then say I'm gonna substring three characters So now give me like the K of three characters afterwards. So I'll give me one on one one So that's a good part about this. I just have to substring my K I know in like Java or like I don't even know I think Python I'm not sure about Python. I know about job is that you have to actually specify like your ending index and that's kind of annoying here because Like you would have to like K minus I plus one or something That would be like your ending index, but this is good because in C plus plus you could just do this And they'll give you like one one Okay, then I have my variable sum and then here I'm just gonna loop through my small substring group So one on one is my first up string group And I'm just gonna convert each character of the of my small group into its corresponding number So here one one on one it would be like this one would be become the actual number one This would become an actual number one and this would become an actual number one So this just converts it to like its corresponding digit Right each of the character into a corresponding digit and I just add add it up So then this sums up all the digits in each of the small groups and then yeah, I do convert it to a two string My new sum and then I just append it at the end of my new string So in the end after we go through all these groups, it'll be like 3 4 6 5 it'll be 3 4 6 5 and Then yeah, then then I said s is equal to that Because that'll be our new string and then we repeat this until our size of our s is less than or equal to k Right because if while it's greater than k it's gonna keep doing this and reduce its size and at the end The size of s will be less than or equal to k and then we just return it So yeah, that's the gist of this problem It's not really that hard Yeah, like this is an easy problem, I think I did in like 10 minutes or something so Yeah, that's pretty that's pretty fast Hope you guys enjoyed this video right come subscribe I'll upload another video because yesterday I didn't upload one but yeah, I'll upload another video for the next problem Yeah, peace