Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,060 --> 00:00:05,470
OK, so now let's try to solve it together, shall we?
2
00:00:06,340 --> 00:00:09,400
First of all, let's also create maybe additional, I don't know.
3
00:00:09,400 --> 00:00:11,860
Let's just use some define size for.
4
00:00:12,910 --> 00:00:15,850
And let's create our array.
5
00:00:16,000 --> 00:00:19,360
So let's use an array of integers, doesn't really matter.
6
00:00:19,390 --> 00:00:19,750
OK?
7
00:00:19,780 --> 00:00:24,110
Because we are simply doing it like they're so innocent.
8
00:00:24,130 --> 00:00:32,110
Let's go with array of values of values, error of size, and it will be initialized through the following
9
00:00:32,110 --> 00:00:35,470
values of five, four, seven and three.
10
00:00:36,440 --> 00:00:36,860
OK.
11
00:00:37,550 --> 00:00:38,090
That's it.
12
00:00:38,660 --> 00:00:41,950
So you could read these values from the user.
13
00:00:41,990 --> 00:00:47,480
You could do whatever you like, but for now, we already know how to read values from the user, how
14
00:00:47,480 --> 00:00:48,350
to work with them.
15
00:00:48,740 --> 00:00:59,510
So now what interests us is how we can simply make this algorithm of rotating to the left a given array
16
00:00:59,510 --> 00:01:00,560
by one position.
17
00:01:01,340 --> 00:01:03,170
So what is the main logic behind it?
18
00:01:03,200 --> 00:01:04,220
What should be done?
19
00:01:04,670 --> 00:01:05,390
What do you think?
20
00:01:05,720 --> 00:01:06,830
What should be done?
21
00:01:06,860 --> 00:01:07,280
OK.
22
00:01:08,390 --> 00:01:12,890
So how can we take all of these elements and rotate them to the left?
23
00:01:13,430 --> 00:01:22,070
If we would say, for example, like Valley, you say you are OK, values IRR at index, let's go size
24
00:01:22,070 --> 00:01:22,910
minus one.
25
00:01:24,590 --> 00:01:25,340
Equals.
26
00:01:26,410 --> 00:01:28,390
To values a rather.
27
00:01:29,380 --> 00:01:37,510
Values air at index zero, then that can be a problem, because after this operation, this value of
28
00:01:37,510 --> 00:01:40,150
five would come here, right?
29
00:01:40,150 --> 00:01:43,240
And the value of three will no longer exist.
30
00:01:44,170 --> 00:01:46,150
OK, so that's a problem.
31
00:01:47,630 --> 00:01:48,800
That's one problem.
32
00:01:49,100 --> 00:01:53,600
The next problem is how you rotate all the other elements to the left.
33
00:01:54,320 --> 00:01:56,870
Well, that's actually not the.
34
00:01:57,790 --> 00:02:05,140
The most difficult thing in this exercise, because that's going to be probably a very simple loop that
35
00:02:05,140 --> 00:02:09,850
will start from equal to one until I is less than size, right?
36
00:02:10,150 --> 00:02:17,020
And then on every iteration you will simply use like values they are at index I equals two values.
37
00:02:17,030 --> 00:02:21,910
Zero rate index minus one equals two values that are at Index II.
38
00:02:21,940 --> 00:02:24,010
OK, so that's one of the options.
39
00:02:25,240 --> 00:02:27,330
So that's about the for a loop of these parts.
40
00:02:27,340 --> 00:02:28,660
But what about the others?
41
00:02:29,080 --> 00:02:37,780
So what is important in this exercise is to understand that the precedence in this case who will be
42
00:02:37,780 --> 00:02:40,450
done before the other is very important.
43
00:02:41,110 --> 00:02:48,640
So what will we will do is the following we will see that we will create additional variable.
44
00:02:49,590 --> 00:02:58,380
OK, we'll create like end temp, OK, temporary variable, and we will store inside of these temp variable.
45
00:02:58,830 --> 00:03:05,070
We will store what we will store the value of error at index zero.
46
00:03:05,820 --> 00:03:08,160
So we will say that values.
47
00:03:09,600 --> 00:03:13,590
IRR at index zero, that would be the first step.
48
00:03:14,500 --> 00:03:18,610
OK, so we have these temp with a value of five.
49
00:03:19,960 --> 00:03:23,350
Then what we will do is we will rotate left.
50
00:03:24,190 --> 00:03:26,020
I will show you in the code in a minute.
51
00:03:26,320 --> 00:03:27,370
Rotate left.
52
00:03:27,820 --> 00:03:38,800
All elements, all elements, OK, all elements from AI equal to one up to AI less than size.
53
00:03:39,160 --> 00:03:43,510
So I'm just writing down the algorithm the main steps that we are going to do.
54
00:03:44,770 --> 00:03:48,170
So after this operation, what we will get in the array?
55
00:03:48,190 --> 00:03:52,090
OK, I just want to show you after this operation.
56
00:03:52,420 --> 00:03:57,040
OK, rotate left all the elements from equal to one two, i.e. less than size.
57
00:03:57,250 --> 00:04:01,900
We will have four, seven, three and three.
58
00:04:01,930 --> 00:04:04,120
OK, this will be a duplicate that you will see.
59
00:04:04,810 --> 00:04:07,180
And after this one will be over.
60
00:04:07,510 --> 00:04:16,930
We will be able to say that values a RA at the last index, which is size minus one, will be equal
61
00:04:16,930 --> 00:04:17,470
to what?
62
00:04:18,770 --> 00:04:25,730
Did a value inside variable Tim, so we did not lose anything, neither from the left side nor from
63
00:04:25,730 --> 00:04:26,330
their white one.
64
00:04:27,580 --> 00:04:30,040
OK, so that's the whole explanation about it.
65
00:04:30,370 --> 00:04:34,090
And that's the main steps that need to be taken care of.
66
00:04:34,960 --> 00:04:41,290
Now with that being said, I hope it's clear so far what we will do is we will write the actual code
67
00:04:41,290 --> 00:04:41,710
for it.
68
00:04:42,220 --> 00:04:46,570
So let's create additional variable that will assist us in the process of looping.
69
00:04:46,570 --> 00:04:56,050
So I, in what we will do, will create a variable and will also use the term variable for storing these
70
00:04:56,050 --> 00:05:03,160
values so that the left most element or the right most element will not be overwritten.
71
00:05:04,330 --> 00:05:11,470
So now what we will do is we will say temp equals two values, they are wrong at one index at index
72
00:05:11,470 --> 00:05:12,160
zero.
73
00:05:12,520 --> 00:05:13,090
Awesome.
74
00:05:14,050 --> 00:05:21,220
Then what we will do is we will do a for loop and for a loop that starts from IE equal to one.
75
00:05:21,610 --> 00:05:25,750
As long as I is less than size right, so far, so good.
76
00:05:26,140 --> 00:05:27,070
I + +.
77
00:05:28,500 --> 00:05:41,280
And we will say that values there come on at Index II minus one will be equal to value, 0r at Index
78
00:05:41,280 --> 00:05:41,610
I.
79
00:05:44,450 --> 00:05:44,990
OK.
80
00:05:45,020 --> 00:05:46,070
Is it enough?
81
00:05:47,390 --> 00:05:51,740
So what we do is we basically, first of all, took these value of five.
82
00:05:51,800 --> 00:05:56,580
Put it aside, then we simply said, OK, so let's start and copy.
83
00:05:57,230 --> 00:05:59,900
OK, I'm just going to map it to you right now.
84
00:06:01,830 --> 00:06:03,990
So that's basically what we do.
85
00:06:04,140 --> 00:06:08,160
We take these value offshore and put it inside here.
86
00:06:08,310 --> 00:06:12,710
OK, so we say at index zero, put the value from index one.
87
00:06:12,720 --> 00:06:13,890
So here we go four.
88
00:06:14,550 --> 00:06:21,050
Then we take the same four, seven three and basically we are done right.
89
00:06:21,210 --> 00:06:22,800
Because that's the last element.
90
00:06:23,130 --> 00:06:26,320
Four ice equals to size minus one.
91
00:06:26,340 --> 00:06:28,080
So that's the last element.
92
00:06:28,290 --> 00:06:29,850
And we put it in the previous one.
93
00:06:30,720 --> 00:06:36,810
So make sure that you start from equal to one because there is also an option to start with equal to
94
00:06:36,810 --> 00:06:37,380
zero.
95
00:06:37,650 --> 00:06:44,730
But then you will need to make sure that you do not go up until I's list in size, but rather ice less
96
00:06:44,730 --> 00:06:46,230
than size minus one.
97
00:06:46,440 --> 00:06:50,910
Otherwise, in this approach, you will probably make sure you did not.
98
00:06:51,270 --> 00:06:56,190
But if you did this way, you are probably exceeding the size of the array.
99
00:06:57,000 --> 00:06:57,270
OK.
100
00:06:57,300 --> 00:07:01,320
The boundaries are awesome, so that's what we have at this moment.
101
00:07:01,830 --> 00:07:09,030
And finally, all that remains once we are out of this for a loop is to say, OK, instead of this value,
102
00:07:09,030 --> 00:07:17,790
we will use the value of faith in the value of five was stored inside the 10 variable and what index.
103
00:07:19,070 --> 00:07:24,650
These value has this value, this element is with index size minus one.
104
00:07:25,710 --> 00:07:29,970
So that's why we are going to do the following we will say values there are.
105
00:07:31,140 --> 00:07:35,040
At index size minus one will be equal to temp.
106
00:07:35,220 --> 00:07:41,670
OK, of course, all of that, not under the for a loop that's going to be right afterwards.
107
00:07:43,560 --> 00:07:44,190
All right.
108
00:07:45,570 --> 00:07:47,010
Is it clear, guys?
109
00:07:47,730 --> 00:07:49,020
I really hope it is.
110
00:07:49,410 --> 00:07:59,430
And basically after this operation, we have mustered and completed a story about that a program that
111
00:07:59,430 --> 00:08:03,630
should rotate left a given a three by one position.
112
00:08:05,000 --> 00:08:09,800
So you can try to print it out, okay, you can add the printing functionality, you can print this
113
00:08:09,800 --> 00:08:13,670
array to make sure that it works, bring the array, whatever you like.
114
00:08:13,900 --> 00:08:22,940
OK, it doesn't really matter because in this exercise, we basically try to focus and to make the best
115
00:08:23,330 --> 00:08:28,400
in order to implement the logic, the algorithmic approach behind it.
116
00:08:28,940 --> 00:08:31,520
Printing, you already know by now how to do so.
117
00:08:31,520 --> 00:08:32,360
You can test it out.
118
00:08:32,660 --> 00:08:35,480
Always just end the associated lines of code.
119
00:08:37,520 --> 00:08:43,280
OK, so later on when you proceed and when you become better and better are developers.
120
00:08:43,610 --> 00:08:50,120
You will see how you can take all of these functionality and put it inside a totally separate function
121
00:08:50,600 --> 00:08:56,720
that will be called like, I don't know, rotates left by one position.
122
00:08:57,290 --> 00:09:04,550
And this function will be capable of receiving an array and basically just making one rotation to the
123
00:09:04,550 --> 00:09:04,910
left.
124
00:09:06,200 --> 00:09:09,280
OK, but for now, that's the main important part.
125
00:09:09,290 --> 00:09:11,000
We have created this program.
126
00:09:11,270 --> 00:09:13,070
We are ready to move on.
127
00:09:13,100 --> 00:09:21,980
So this exercise is the basis for a couple of additional exercises that I will show you in about a couple
128
00:09:21,980 --> 00:09:23,390
of minutes, hopefully.
129
00:09:24,710 --> 00:09:26,120
So thank you guys for watching.
130
00:09:26,150 --> 00:09:27,320
Keep on practicing.
131
00:09:27,350 --> 00:09:30,530
Keep on moving forward and you are bound to succeed.
132
00:09:31,430 --> 00:09:32,390
I'll see you next time.
133
00:09:32,570 --> 00:09:33,050
Bye.
11974
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.