Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
What is going on, ladies and gentlemen, and welcome back.
Welcome back to where.
Welcome back to another very, very interesting video.
Interesting exercise to our in our programming course.
So what are we going to do now?
What are we going to do now is to write a program that should calculate and print the largest sum of
two adjutants element in the array.
So we are going to initialize some array or maybe to read the values from the user, probably able initialize
it to make it a little bit quicker for you.
And once we initialize the array, what do we have to find out is basically the largest sum of two American
elements, basically of two neighbors, OK, two neighbors in this array and simply to print this result
of the screen.
So first of all, I hope the instructions are clear.
And second, we can take a look at, of course, two examples to make sure that we understand it.
So here we have our first example where we have like an array with one, four, three, seven and one,
OK, that's an array of size five like for example.
And we can see that this array has five elements and we are going to find the largest sum of two magic
and elements of two neighbors.
So one in four gives us a value of five, four and three gives us the value of seven.
Three and seven gives us a value of ten in seven.
One gives us a value of eight.
So basically, the largest sum is definitely ten, because we know that three plus seven gives us them,
and that's the largest sum between our neighbors in disarray between two neighbors.
In the second example, just for those of you guys who did not clearly understand the first example.
So the second example, we take every time two elements and see what the sum will be, basically would
do the following thing for every in each one of the elements here and find out what is the largest sum.
And then finally print it out to five and seven in this case is the largest sum in this array.
Awesome.
All right, so with that being said, I think a couple of minutes tried to come up with a solution and
let's solve it together.
So the first thing that we are going to do is, first of all, just to create the array so into a RAH,
let's make it of size five.
So it is of cease fire and no all it's also initialized to have these values right here.
Let's just copy that.
Let's just copy that.
OK, so one, four, three, seven one.
And now let's start to teach you to think of the logic.
So how do you think we should tackle it?
So basically, first of all, we know that probably chances are high that we are going to to need to
iterate over all the elements.
Right.
So for that, let's create AI and use some loop.
So for AI equals to zero, AI is less than five.
Let's define these five as the size here.
You find size five in here, we will use the size.
Size or slumpy, plus, plus, all righty, so that's what we have so far and in the for loop, we are
simply going to iterate over all of these elements, one after the other, OK, and see what happens
in how basically things are going to look like.
But the question is how basically, what are we?
Should we store the maximum?
OK, so let's create additional variable.
Call it mux some.
And my suggestion, maybe we can sort of course, there are a couple of ways to solve it, but let's
assume that the maximum sum, right, if we start to work from left to right, will be the sum of the
first element.
And the second element, the sum so far.
Right.
The mux sum so far.
So we'll say that, Max, some will equal to HRR at index zero plus E R indexed one.
OK, that's how we are going to do it.
And now we simply have to like to modify these.
These are for loop enough to start from Ecorse to one from zero, but one I equals to one and then on
every time we're going to take the element and the element on its right.
So that's why we need also to set up the stubborn condition not to end like it was supposed to be on
this index, on the index for in this case, but rather to stop it.
Index three, since we already take into account the plus one so that we will not exceed the size of
the array.
OK, so inside of these for a loop, there is a simple condition that we are going to ask if the Moxham
meaning the maximum so far is less all right if it's less than a year are index by plus a R right plus
one.
OK, if the maximum sum so far is less than the current, some of the two neighbors.
OK, so let's write it down.
If maximum so far is less OK, maximum so far is less than is less then than what is less than the sum
of current neighbors.
Then that means we found out, we found out in you maximum some two neighbors, so like some will be
equal to ARRL because I lost everything I plus one.
OK, so we simply go every time over two elements and store the maximum so far in the maximum, so far
as less than two given elements like in this case, where in this case then we simply update the maximum
sum.
Right.
And finally we will print out the result.
Print F maximum.
Some go to neighbors, neighbors equals to percentage.
And he will specify also marks some amazing.
Now let's build and run it and see how it goes.
What's going on?
OK, so maximum sum of two neighbors equals two.
What do you think it's equal to?
What do you think?
Just before that, let me simply fix this problem.
We said here we should specify size minus one right now and taking are not going like exceeding the
array dimensions.
So feel run it.
There you go.
Maximum sum of two neighbors equals 10.
OK, so we now have three and seven equals to equal to 10.
And if we will, I don't know, like let's play with it to make sure that also it works as expected.
So, so.
So maximum sum of two neighbors equals 12 also.
That's exactly how it was done in the examples.
So I hope everything is clear to you guys.
Keep on practicing.
Also, you can update these program a little bit into also to find out and to like to store.
OK, that's a minor change.
But to find and store also the the two numbers, the two values of the neighbors that are part of the
largest sum.
OK, so that's kind of an upgrade that you can add on your own so that finally you will print like maximalism
of two neighbors, which are these one?
And this one equals to Moxham.
OK, so that's kind of an upgrade that I'm living to you.
I think you can handle it and simply think of what maybe two additional variables you should hold and
when you should update them.
Thank you so much for watching.
My name is Vlad.
This is Alphatech and continue on practicing.
I'll see you on the next section.
Remedios now depends.
Good bye, guys.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.