 What's up guys, my name is Michael and welcome to my YouTube chat today we are going to go over left rotation operation. So basically a left rotation operation on an array of sides and shifts each of the arrays elements one left one unit to the left. So now given D integer D we're gonna just have to shift everything D times to the left and return the result. Okay, so this is actually not that hard. So what we could do is we could write a method that just shifts everything to the left by one, and then we just loop through it and just keep shifting D times. Okay, so I actually wrote this already. So I'm just going to explain the code what I did. So here this is basically what I'm doing to shift everything to the left. All right, so I created a variable called start that is going to equal to the first element. So here, let's say I wanted to shift everything here to the left, right? So we have 12345. So when we mean shift everything to the left by one, we mean that this one is going to become a two. This two is going to become a three. This three is going to become a four. And this four is going to become a five, right? And then the starting one is going to now going to go to the end, right? Because when we shift it to the left, there's nothing in the left anymore. So what's now it's going to happen is go to the end. So what I did was I just started from the beginning, I set a variable to equal to the start right to start is going to equal to the beginning of the first value, right at zero. And I just loop through from zero to the end. And then I'm just going to set each element to equal to that was my timer. That was my laundry timer. Sorry. Um, so I just said each element from the first one to equal to the next one. So r at i is going to equal to r i plus one. So what this is going to do if we're looping from beginning, it's going to set this one to become the two, this two is going to become the three, this three is going to become the four, this four is going to become the five. And this last value of five, I need to replace this right with the first value of one. So that's what I do here at the end. I said r at size minus one, which is the end is going to equal to start. And then now what I'm doing this is I'm just going to do this D times. So I'm going to do while loop and then do this D, D is greater than zero D minus minus. So then I do this D times and then yeah, then that after that, I just returned my array. And yeah, it basically passed the solution test cases. So let's actually look at other people solutions. I know that there is a way to do this with, yeah, is way to do this just by using modules. Although they, I think they are creating a new array. Okay, that's just yeah, so here, what they're doing is they're creating a new array. And then what they're doing is they're going to loop through from the beginning. And they're just going to like calculate the new index to where it's going to be at. So what that means is they take the old index we're at and we're going to subtract it from D. And then because it's going to be going negative, we need to loop around the array. So one way to actually loop around the array is just to add by end. And then once we add by end, sometimes you might go over the array. So what they do is a mod by end. So then it'll come back in a circle. So that's what this new thing is and then rotation array, the new index is going to be equal to value at the old index. So we could actually do this code right now actually, if you don't want to use two loops. So we could actually do that right now. Of course, this requires creating a new array though. So it's great new array, it's going to be called new R2 R dot size. Okay, so what we're going to do is we're going to loop through from current index to the end. And what we're going to do is that we're going to actually take current index, subtract it by D. And then we're going to add it by end. Right. And is the size of our array. So we're going to add it by D, subtract it by D, add it by end, and then we're going to modify and take this very modified by end. And this is going to be R2, and this is going to be R at I. And what this is doing is basically the same thing of we said before is just going to, instead of shifting it one by one, we're just going to like take it for shifting this by two, this three is going to jump to two, right. And then this two is going to jump backwards, but because we're going two rotations down and it's out of bounds in the array, we're going to add it by the length of the original array so it loops back. So once it loops back, we could, that'll be our new position where we're putting it. But sometimes it goes overboard, like it goes overboard. If I add like at this point, add two, actually, at this one point, I go down by two, it goes like out of the array. So yeah, we have to subtract the D times and add by N, which is the size of the array. And then we mod it. So that goes back to original. So yeah, let's submit this code. I want just to make sure that this works. Yeah. So this one also works. Yeah. So this is how you do it with just one for loop. Yeah. D minus, I minus D plus N mod by N. Hope you guys enjoyed this video is all that's all there is to left rotation rate comms subscribe. I'll check you guys later. Peace.