 How you guys doing Mike the coder here today? We're gonna go over increasing array So basically you're given an array of n integers you want to change this array so that each element is increasing So in one move you could increase the value of one element by one now What is the question is that what is the minimum number of moves required? so what do I mean by that so let's actually Get a picture and put in paint first because I I Now have my pen so I could actually do this really fast and explain the input For these problems. So let's say we have this array. I think this is a crop And hold up. Let me just real quick do this real quick So let's say that we have this array of five two So three two five one seven so what what we want to do is we want to Find the minimum minimum moves minimum minimum number of moves to make this increasing So when they say increasing they're not actually mean like one is like large in the other one They mean that so that every element is at least as large as the previous one So what that means is like in this case I could change this two into a three right and then this Then this would take one move right it would take one move. So that's a one move and then this five Since it's already greater than three. So I could just leave that alone Then if I want to increase this this Make this increasing. So what do I do? So one is less than five. So in order to make this increasing I have to add Probably four I need add four to make it into five right so then this becomes five so then our final array and the number of moves that this actually took was a plus four by the way because We had to increase this out number one Four times in order to get it to equal to five right? We had to increase this number one four times So that's why each move has like a cost of one to do each move. So that's why that's the case. So Yeah, so our final array would be Three three five five seven Right three three five five seven and this is now increasing right all the values are increasing They're at least either the same as the previous one or they're increasing So because of this what is now the total cost the total cost this did was one plus four Which is going to be five. So now the minimum cost was answer was five So, how do you do this problem? A simple way is to either Keep increasing it by one. So keep increasing it by one To make it either equal to the previous element right equal to the previous element if it's less than it so in this case for two I Increased it by one once so I got three so that that did a plus one and for this number one I increased it by one four times to get get it to five Because I wanted this one to equal to this five, right? I wanted this to equal to that So increased it four times to get five So then in there in the end our array is increasing. So, yeah, that's pretty much the gist of this problem I'll just show you guys the code now because Actually got a seed on this one go. So here's the code. It's actually not that difficult So The first part is just reading in the array. So read in n read in Create their ID just reads in it. So the cost for each count I'm going to have equal to x right equal to x Then I'm just gonna loop from one to the end of the array. So I'm gonna loop from this one I'm gonna loop all the way to the end of the array and what I'm going to do is If my current value is smaller than the previous one So this two is smaller than this three, right? So what I'm going to do is I'm gonna have this the difference. I'm gonna get the difference of each of them So in order to increase this two to become three, I'm gonna take the absolute value of two minus three, right? Or you could do three minus two Regardless, that's the number of moves. It would take Increasing each element by one increasing this element by one to get it to the same one as the previous one. So I I just subtract it. So I did absolute value of the array minus the previous one and take the absolute value of that and then Then I'm gonna increase my cost. So my cost is x currently, right? So I'm gonna this the total number moves. I'm just gonna take x plus equal to new value, okay? then This is just to make sure that I update the array You don't have to because they're just asking you for the the cost, right the total minimum number of minimum number of Moves it takes to do it. So to do that. I just did You just have to do x plus equal to this new value of the absolute value of the difference to get it to Equal to it and then you just print it out print out x so here I actually modified the array to make it plus equal to new value You could do that if you want to actually change this to to become a three and changes one to become a five That'll do that. But um, yeah, you don't actually have to do this. This is just like this part of Modifying the array. That's just like extra work But yeah, that's pretty much the gist of the code because all we have to do after that We just have to print out the number of moves of x which is our cost. So that's the thing we're doing. So yeah Yeah, that's all the moves that we took and Hope you guys enjoyed this video. Hope you guys enjoyed this video. It's not that hard This problem is not that hard. I know you guys ask if I should post a code the code is actually not that difficult like Like the only thing you need to know is just hashtag to find a long and I'm using that for these values You could use integer. I think Or whatever. I just like to use long long because like Yeah, it's just easier to do it. Um, I think it's better if I use better variable names for x But this is just the gist of the code. So yeah, read in the array if it's smaller than the previous one We're just going to add equal to the difference between the two values and then we're just going to print it So we're gonna. Yeah, that's basically it. That's a total of it. Ready to come subscribe. I'll check you guys later. Peace