Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,590 --> 00:00:06,440
What is going on, ladies and gentlemen, and welcome back.
2
00:00:06,530 --> 00:00:08,060
Welcome back to where.
3
00:00:08,600 --> 00:00:13,040
Welcome back to another very, very interesting video.
4
00:00:13,040 --> 00:00:17,890
Interesting exercise to our in our programming course.
5
00:00:18,800 --> 00:00:21,730
So what are we going to do now?
6
00:00:21,980 --> 00:00:30,440
What are we going to do now is to write a program that should calculate and print the largest sum of
7
00:00:30,440 --> 00:00:33,680
two adjutants element in the array.
8
00:00:33,980 --> 00:00:41,060
So we are going to initialize some array or maybe to read the values from the user, probably able initialize
9
00:00:41,060 --> 00:00:42,920
it to make it a little bit quicker for you.
10
00:00:43,790 --> 00:00:53,270
And once we initialize the array, what do we have to find out is basically the largest sum of two American
11
00:00:53,390 --> 00:01:01,580
elements, basically of two neighbors, OK, two neighbors in this array and simply to print this result
12
00:01:01,580 --> 00:01:02,130
of the screen.
13
00:01:03,290 --> 00:01:06,880
So first of all, I hope the instructions are clear.
14
00:01:07,280 --> 00:01:12,720
And second, we can take a look at, of course, two examples to make sure that we understand it.
15
00:01:13,820 --> 00:01:22,610
So here we have our first example where we have like an array with one, four, three, seven and one,
16
00:01:23,330 --> 00:01:26,450
OK, that's an array of size five like for example.
17
00:01:27,410 --> 00:01:35,930
And we can see that this array has five elements and we are going to find the largest sum of two magic
18
00:01:35,930 --> 00:01:37,450
and elements of two neighbors.
19
00:01:37,940 --> 00:01:44,390
So one in four gives us a value of five, four and three gives us the value of seven.
20
00:01:45,110 --> 00:01:48,420
Three and seven gives us a value of ten in seven.
21
00:01:48,470 --> 00:01:50,870
One gives us a value of eight.
22
00:01:51,900 --> 00:01:59,480
So basically, the largest sum is definitely ten, because we know that three plus seven gives us them,
23
00:01:59,490 --> 00:02:05,430
and that's the largest sum between our neighbors in disarray between two neighbors.
24
00:02:06,450 --> 00:02:13,480
In the second example, just for those of you guys who did not clearly understand the first example.
25
00:02:13,530 --> 00:02:21,180
So the second example, we take every time two elements and see what the sum will be, basically would
26
00:02:21,180 --> 00:02:29,130
do the following thing for every in each one of the elements here and find out what is the largest sum.
27
00:02:29,250 --> 00:02:36,420
And then finally print it out to five and seven in this case is the largest sum in this array.
28
00:02:37,980 --> 00:02:38,520
Awesome.
29
00:02:39,540 --> 00:02:48,750
All right, so with that being said, I think a couple of minutes tried to come up with a solution and
30
00:02:49,260 --> 00:02:50,420
let's solve it together.
31
00:02:51,330 --> 00:02:57,530
So the first thing that we are going to do is, first of all, just to create the array so into a RAH,
32
00:02:57,580 --> 00:02:59,250
let's make it of size five.
33
00:03:01,100 --> 00:03:07,510
So it is of cease fire and no all it's also initialized to have these values right here.
34
00:03:07,520 --> 00:03:08,990
Let's just copy that.
35
00:03:11,650 --> 00:03:13,810
Let's just copy that.
36
00:03:14,230 --> 00:03:16,160
OK, so one, four, three, seven one.
37
00:03:16,840 --> 00:03:22,420
And now let's start to teach you to think of the logic.
38
00:03:23,200 --> 00:03:24,940
So how do you think we should tackle it?
39
00:03:25,570 --> 00:03:31,750
So basically, first of all, we know that probably chances are high that we are going to to need to
40
00:03:31,750 --> 00:03:33,520
iterate over all the elements.
41
00:03:33,640 --> 00:03:33,990
Right.
42
00:03:34,000 --> 00:03:37,440
So for that, let's create AI and use some loop.
43
00:03:37,450 --> 00:03:42,610
So for AI equals to zero, AI is less than five.
44
00:03:42,790 --> 00:03:45,690
Let's define these five as the size here.
45
00:03:48,400 --> 00:03:53,270
You find size five in here, we will use the size.
46
00:03:56,720 --> 00:04:04,460
Size or slumpy, plus, plus, all righty, so that's what we have so far and in the for loop, we are
47
00:04:04,460 --> 00:04:11,480
simply going to iterate over all of these elements, one after the other, OK, and see what happens
48
00:04:11,480 --> 00:04:15,050
in how basically things are going to look like.
49
00:04:15,950 --> 00:04:19,040
But the question is how basically, what are we?
50
00:04:19,040 --> 00:04:20,700
Should we store the maximum?
51
00:04:20,720 --> 00:04:23,120
OK, so let's create additional variable.
52
00:04:23,120 --> 00:04:24,730
Call it mux some.
53
00:04:25,520 --> 00:04:32,090
And my suggestion, maybe we can sort of course, there are a couple of ways to solve it, but let's
54
00:04:32,090 --> 00:04:39,740
assume that the maximum sum, right, if we start to work from left to right, will be the sum of the
55
00:04:39,770 --> 00:04:40,580
first element.
56
00:04:40,580 --> 00:04:43,220
And the second element, the sum so far.
57
00:04:43,220 --> 00:04:43,480
Right.
58
00:04:43,490 --> 00:04:45,080
The mux sum so far.
59
00:04:45,560 --> 00:04:56,210
So we'll say that, Max, some will equal to HRR at index zero plus E R indexed one.
60
00:04:56,750 --> 00:04:58,760
OK, that's how we are going to do it.
61
00:04:59,810 --> 00:05:03,470
And now we simply have to like to modify these.
62
00:05:05,090 --> 00:05:13,670
These are for loop enough to start from Ecorse to one from zero, but one I equals to one and then on
63
00:05:13,670 --> 00:05:17,670
every time we're going to take the element and the element on its right.
64
00:05:18,140 --> 00:05:24,770
So that's why we need also to set up the stubborn condition not to end like it was supposed to be on
65
00:05:24,770 --> 00:05:30,260
this index, on the index for in this case, but rather to stop it.
66
00:05:30,260 --> 00:05:38,660
Index three, since we already take into account the plus one so that we will not exceed the size of
67
00:05:38,660 --> 00:05:39,050
the array.
68
00:05:40,070 --> 00:05:49,850
OK, so inside of these for a loop, there is a simple condition that we are going to ask if the Moxham
69
00:05:50,660 --> 00:06:01,010
meaning the maximum so far is less all right if it's less than a year are index by plus a R right plus
70
00:06:01,010 --> 00:06:01,340
one.
71
00:06:01,730 --> 00:06:09,710
OK, if the maximum sum so far is less than the current, some of the two neighbors.
72
00:06:10,400 --> 00:06:11,750
OK, so let's write it down.
73
00:06:11,770 --> 00:06:27,020
If maximum so far is less OK, maximum so far is less than is less then than what is less than the sum
74
00:06:27,560 --> 00:06:30,170
of current neighbors.
75
00:06:31,980 --> 00:06:41,330
Then that means we found out, we found out in you maximum some two neighbors, so like some will be
76
00:06:41,330 --> 00:06:47,000
equal to ARRL because I lost everything I plus one.
77
00:06:48,260 --> 00:06:55,270
OK, so we simply go every time over two elements and store the maximum so far in the maximum, so far
78
00:06:55,270 --> 00:07:02,090
as less than two given elements like in this case, where in this case then we simply update the maximum
79
00:07:02,090 --> 00:07:02,330
sum.
80
00:07:03,560 --> 00:07:03,850
Right.
81
00:07:03,860 --> 00:07:06,410
And finally we will print out the result.
82
00:07:06,410 --> 00:07:08,840
Print F maximum.
83
00:07:10,040 --> 00:07:18,470
Some go to neighbors, neighbors equals to percentage.
84
00:07:20,080 --> 00:07:24,810
And he will specify also marks some amazing.
85
00:07:25,640 --> 00:07:30,020
Now let's build and run it and see how it goes.
86
00:07:31,170 --> 00:07:32,270
What's going on?
87
00:07:32,300 --> 00:07:36,820
OK, so maximum sum of two neighbors equals two.
88
00:07:37,400 --> 00:07:38,740
What do you think it's equal to?
89
00:07:39,560 --> 00:07:40,430
What do you think?
90
00:07:41,720 --> 00:07:45,080
Just before that, let me simply fix this problem.
91
00:07:45,080 --> 00:07:52,700
We said here we should specify size minus one right now and taking are not going like exceeding the
92
00:07:52,790 --> 00:07:53,680
array dimensions.
93
00:07:53,690 --> 00:07:54,840
So feel run it.
94
00:07:55,300 --> 00:07:56,390
There you go.
95
00:07:56,420 --> 00:07:59,580
Maximum sum of two neighbors equals 10.
96
00:08:00,400 --> 00:08:04,040
OK, so we now have three and seven equals to equal to 10.
97
00:08:05,090 --> 00:08:11,160
And if we will, I don't know, like let's play with it to make sure that also it works as expected.
98
00:08:12,020 --> 00:08:12,520
So, so.
99
00:08:12,520 --> 00:08:17,240
So maximum sum of two neighbors equals 12 also.
100
00:08:17,300 --> 00:08:22,060
That's exactly how it was done in the examples.
101
00:08:22,640 --> 00:08:25,130
So I hope everything is clear to you guys.
102
00:08:27,530 --> 00:08:28,610
Keep on practicing.
103
00:08:28,630 --> 00:08:35,900
Also, you can update these program a little bit into also to find out and to like to store.
104
00:08:36,050 --> 00:08:37,550
OK, that's a minor change.
105
00:08:37,550 --> 00:08:45,530
But to find and store also the the two numbers, the two values of the neighbors that are part of the
106
00:08:45,530 --> 00:08:46,590
largest sum.
107
00:08:47,270 --> 00:08:55,240
OK, so that's kind of an upgrade that you can add on your own so that finally you will print like maximalism
108
00:08:55,250 --> 00:08:58,280
of two neighbors, which are these one?
109
00:08:58,280 --> 00:09:00,890
And this one equals to Moxham.
110
00:09:01,070 --> 00:09:04,090
OK, so that's kind of an upgrade that I'm living to you.
111
00:09:04,100 --> 00:09:11,930
I think you can handle it and simply think of what maybe two additional variables you should hold and
112
00:09:11,930 --> 00:09:13,740
when you should update them.
113
00:09:14,750 --> 00:09:15,920
Thank you so much for watching.
114
00:09:15,950 --> 00:09:16,770
My name is Vlad.
115
00:09:16,820 --> 00:09:19,480
This is Alphatech and continue on practicing.
116
00:09:19,490 --> 00:09:22,460
I'll see you on the next section.
117
00:09:22,460 --> 00:09:24,480
Remedios now depends.
118
00:09:25,130 --> 00:09:25,760
Good bye, guys.
11012
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.