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
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
Oh, right.
So I think this process was not an easy one for you, but still, if you're here, I want to thank you
and I want to say that you are doing great because even coming to the solutions video is not an easy
task after these.
Not so easy exercise.
So let us get started.
All right.
And what I want us to do, first of all, is basically to try to think even how would you approach this
exercise?
So let's say that we have here, let me get my pen.
OK, so let us take a look at this example.
Four, three, eight.
OK, so since we know that we are going to use a recursion function that probably probably there is
going to be some recursive calls.
Right.
For or recursive instances.
So let's say there is an instance for an equals two, four, three, eight and then an equals two,
four, three and then an equals to four.
Basically, that's it.
OK, I'm just I'm just trying to like to go over the steps and over your.
Possibly thoughts that you had during the solution, so are and equals two, four, three, eight and
equals two for a three and and equals to four.
So we can say that whenever we reach some point when and he's less than 10, OK, which means it's going
to be it's going to be one digit number, then in this case, we have to like to think what should be
returned.
So that's very interesting.
Guys, what do you think should be returned here?
Should it be if if that's the case?
Because because I think that a lot of you guys thought of this way of and what will happen if and is
less than 10, which is something that you would have used for a base case, what do you think should
be returned in such a case?
Should be returned just the value of one, OK, or the value of zero, basically saying we said previously
that we will return one if every digit and that an even possession has an even value as well as every
digit in the opposition will have an odd value.
But here we have like just one one value of one digit.
So how can we say is this position is.
Is this position is more positive, this position is even or odd, so what do you think?
And to be honest, I think it's kind of hard to assess if these four here was at an even or odd position,
since there may be also another number, like four or three, four, four, three, eight, OK, and
it will basically it's a lot like this, but yeah, four four, four, three, eight.
And it will basically look something like this.
Right.
So it will look silly.
Not not like this.
So for three, eight, four, three, eight and let's say I don't know, let's say five for example.
So this will be just also the recursion calls for and divided by ten for every recursive call.
So what I want to say by these is that also for at least number and also for this number, the value
of four can be at an even index like here, or it can be in an odd index like here.
Right, because zero.
One, two, three.
So.
The assumption of if is less than 10, then return one or zero, just based on the fact that you have
one digit is not the correct way to go.
So what do you think?
How should we basically approach that?
And one of the things that I suggest to you to understand is the fact that, first of all, for every
natural number you may have for the end itself, OK, for the end itself, that's the very that's the
catch here, let's say, or the basic trick.
So for every M, there are only two options.
OK, two options either.
Either the number of digits is even or odd.
OK, so even.
We're on.
Number of digits, OK, so every number is compromised of digits, so every number goes like this,
like digit one digit too, and so on up until some digit M right every number, this may be one digit
number, two digits number and so on.
And the number of these digits, maybe either odd or even.
OK, so that's the first step that I want you to understand, because that's going to be crucial and
very important for our solution.
So even and odd.
So even and odd does not mean that there is something about the positions that that's just the dust.
That just means that there are even even digits or digits.
So that example here, like twenty six or four, eight, seven, five, I don't know, two digits,
four digits, even number of digits.
Odd will be like three five seven five.
I don't know, something like that.
OK, three digits, one digit odd number of digits.
So let's just on droid here that everything will be also clear to you.
Number of digits.
Awesome.
So that's the number of digits, number of digits, and now what I want us to do is basically to use
the same approach that we used previously by just taking the end and to call these recursive calls.
OK, but these recursive calls are going to have some catch, OK?
On every iteration, I want us to divide the value by a hundred, OK, and to test two.
Basically two are things the value on the rightmost value and the value the other value that I will
just show you in a bit.
OK, the rightmost value and one to each left and we will have two scenarios here.
First scenario is if and is less than 10.
OK, meaning we got one digit and if and is less than a hundred.
OK, so these are going to be our two base cases.
And why is that why do we have to base cases?
Because whenever we will have and deal with our values that have like that have even numbers of digits,
then in this case, every time that you are going to divide it by 100.
OK, then let's say I don't know, let's say four four eight seven five.
You divided by a hundred, you get like forty eight.
So you will always be like in this region.
OK, for all the values that have like a number of digits, even every time you divide by 100, you
will always fall here.
Either way, it's going to be like, no, like these two six, five, four, three, two.
You divided by a hundred and then you divide it by also a hundred.
And then this value is going to be here.
OK, you are never going to reach these base case where you simply have this if and these less than
10 never for even for one number of digits equal to even on the other hand, you are always going to
reach these place for numbers that have an odd number of digits.
So in this case, three will reach here five seven five.
When you divide it by a hundred, you're also going to remain with five and you are going to reach this
place.
So this fact, the differences between these two base cases is actually used to distinguish between
two cases when we have a number of digits and even number of digits and an odd number of digits.
And why is it so useful?
That's useful because it will allow us during the process to know in advance, OK, to compare basically
these two values, the rightmost and one on its left, and simply to build our way up once we know the
position.
OK, so here we will know that if we if any less than one hundred, let's say it will be like four eight.
OK, then in this case we know to check that both of them satisfy the condition, if so, return one,
otherwise return zero.
And then we will have like on the way up four eight seven five and we will check this out and these
out and we will know that this will be always at an even position and this will always be at an odd
position.
OK, so once again, that's not so trivial to grasp at first.
OK, I'm going to write the code and then we are going to go over this visualisation process again,
OK, with a few examples to make sure that everything is clear to you.
So don't worry, you hopefully will understand everything that goes behind the scenes.
OK, so now let us start writing of the solution, guys.
OK, so let's just make sure that I'm recording this.
Yes.
And then I'll start with the solution.
Let's remove everything from here from the screen.
Awesome.
And let's go here and let's call our function, first of all, the type of the function.
What should it be?
Let's stay with an integer.
Right.
Because the two optional values that can be returned from this function are simply either zero or one.
All right.
So.
And let's call it I don't know, I don't know even the or I don't know, um, even on Phonic, let's
call it for now and get some value or some natural number of him.
Awesome.
So we said that we are going to treat mainly to base cases, OK, to base cases.
The first one is when M is less than 10.
And if that's the case, let us see if OK if no if these and modular two equals to zero, if that's
the case, if it a one digit one digit number, OK, one digit number, that simply means that we were
working with on some end value that have in the first place.
And the first recursive call, an odd digit, an odd number of digits, then it means that this digit
OK, this digit right here is going to be at what position at and what do you think.
And even position, right, because again, here is a simple example, four, three, eight, and if
we divided by 100, we simply get these four.
So if we will take a look, these four will be at an even position always.
Right?
Right.
Because every time we are going to divide by 100, it's going to be at an even position.
Awesome.
So if and can be divided by two without the remainder, that means that the value is even also.
And if that's the case, we can assume that we will return one because the condition is satisfied,
otherwise we will return zero because the condition is not satisfied, meaning we have one digit and
its position is even, but the value cannot be divided by two without the remainder.
That means that the final result should be zero because the condition is not satisfied.
This condition here right for returning one.
Awesome.
So now let us proceed for the second base case.
And these base case is basically something like this if and is less than one hundred, meaning it is
a two digits number.
OK, and if that's two digits.
No, that's awesome.
Right.
Because that means we simply are we simply we simply we simply.
What does it mean?
What do you think, if anything, less than one hundred.
What does it mean then.
It means we are we remain with just two digits, OK.
And it will look like we don't have an example here.
So let's say we simply will also make another example.
We will make another example, its example three, and it will be like this.
So five here.
So did it.
And also we will use also like something like this.
OK, so position zero, position zero will have five.
Position one will have eight.
Position two will have three and position three will have four.
OK.
So what do we have here?
What do we have here if AMM is less than 100 hundred, meaning we divided this time by a hundred, we
got forty three, then in this case, we know that we will have two digits.
OK, do digits four and three.
OK, that's the base case we are planning to reach.
So four and three and this three lies on position even and these four will lie on position on OK so
do digits.
Are the rightmost digit at even position.
Right.
Even pause and leftmost, leftmost or left digit is at odd position.
OK, you see, you see what we're doing here so we know we will have two digits and the rightmost digit
that can be accessed by using these and modulo 10 can be accessed.
And it will it is going to be at an even position and the one on its left is going to be at an odd position.
All right, so OK, if that's the case, we are going to see the following if an Modula 10, which is
their rightmost digit, can be divided by two without a remainder.
OK, if it can be divided by two without the remainder.
And also if we take the leftmost digit in such a case and divided by two without a remainder or basically
with the remainder of one.
So if that happens, that will mean that the rightmost digit at the even position is the value is even
and also the left value in between these two digits is an odd value, has an odd value.
And it's also, as we said, at an odd position.
If that's the case, what do you think we should return?
We should return one.
OK, otherwise, of course, we can return zero.
Is that clear?
OK, we just tweeted the two base cases, so that was basically case one base case still in the differences
between them is that these base cases going to be reached.
OK, if we correctly build the following line of code.
If we are, it's going to be reached only for numbers that have been in an odd number of digits.
And these base case is going to be reached for numbers that have only on an even number of digits.
Whoo!
All right, so let us proceed.
And now what we are going to do is basically to ask the following question.
So that's going to be regarding our, um, our recursive call.
So our recursive call is going to be very simple.
We are going to ask we are going to ask if an modula to or basically Modula 10.
Modula Two, which means the rightmost digit, if it is and even digit and also if this digit of digit
on on its left, OK, one on its left, so much about 10 if this digit the rightmost digit and also
the one digit on its left, OK, and divided by 10 modulo 10 can be divided by two.
OK, if that's the case, OK, we are going to assume that if that's the case, we are going to return
the result.
OK, four are these even all function.
Four and a hundred.
OK, so that's very not so intuitive else return zero.
OK, so that's not so intuitive to to grasp at first, but first of all, what I want you to understand
is the distinguished distinguish distinguish we've made between numbers with odd and even number of
digits.
And now regarding these recursive call, I think the best way to understand it is simply to use some
drawing and to use some examples.
OK, so let us start let me get my pen and let's start drawing.
OK, so.
Let's say that we are going to start with this third example, so it's going to be like four, three,
eight five, OK, this condition is false, this condition is false.
And we are going to ask if five in this case, that's five.
If five is even, is there even what do you think?
Is it even know?
It's not even.
But we are checking the even position.
We are checking the even position.
OK, that's the rightmost element, if that's the case.
But it's not, then we simply go to the else and we return zero.
OK, so the result for these will be zero and it kind of makes sense since you can see here and even
position but an odd value.
So that's basically it for this example.
So that's how you find it.
Now, let us proceed to another example.
So let's see what it is.
Let's go a little bit up.
So four, three, eight.
OK, so four, three and four and eight.
OK, so now we are going to let's just remove that so we'll see everything on the screen.
Also the code.
OK, so now we are going to ask the following question.
Condition, false condition, false.
So if the rightmost digit is even.
Yes, it is.
And one on its left, which is three is odd.
Yes it is.
Then we are going to return all four and divided by one hundred, which is four.
OK, so this result basically depends on what it's going to return us for even often.
Four, four.
And if we are going to come here, this is the base case related right to numbers with just odd number
of digits.
Then in this case, this condition is true.
Four is less than 10.
If four can be divided by two without the remainder, that is true.
The value is even and it was at an even position, then we are going to return one.
And also from here we are going to return.
One final result is one.
All the conditions, conditions are satisfied exactly as we explained and expected.
And now let us see the final example.
OK, I hope everything is clear.
Ask me if you have still any questions.
Let us see the final example.
What was it?
What was it?
Three six three six four three five.
OK, so.
That's it, three, six, four, three, five.
OK, so let us check let us check if and Modula 10, which is the rightmost digit, can be divided by
two without a reminder ups.
No, it can be so return to zero.
And there you go.
Basically, you return zero right from the start.
So these are this is it about the examples that I wanted to show you.
Of course, there are a lot of additional examples that we can use, but I think I've covered at least
a few of them to make it more clear to you.
And now I want to simply summarize the steps that we used to solve this exercise.
So.
Step number one was to distinguish between two main scenarios, scenario number one was like to understand
that there should be some sort of different treatment and different solution for situations when you
have an odd or even number of digits in a given number.
OK, so that was the first thing we had to take care of.
And we simply got got got it taken care of at this step.
Of course, if you see it for the first time, this kind of exercise, it's not so easy to grasp and
it's not so trivial to understand the separation between assuming that if there are going to be odd
number of digits, then if you divide it by 100 every time and you reach these kind of time that the
number that digit is going to be at even position.
And here you will have two digits and, you know, like it's very hard at first time.
But now, since you kind of know the basics in the approach, it should be easier for you to solve or
exercises of a similar concept and of a similar complexity.
OK, so that's about it.
And the first place then we have like to understand how to make the recursive call.
So we understood why we're using and divide it by a hundred every time that it will be able to distinguish
for us two cases like here and every time we don't care if we have like numbers of an odd number of
digits or an even number of digits, we don't care about it since we start from there.
Right, OK.
And when we start from there, right.
Every time we will see the rightmost element, it should have a value that is even and one only two
left should have a value that is odd.
Otherwise there is no sense to make any recursive calls and we will simply assume that the return result
should be zero.
OK, so every time we we we since we divide by 100, every time we are going to start like from from
position zero and then from position to and from position four and so on and so forth.
So that makes sense.
OK, and the final distinguish between the two based cases will be handled in these kind of sections.
Who so guys, this exercisable is not an easy one.
I hope you've got a hold of it.
If you still have any questions, feel free to ask them.
And for those of you that know the answers to the questions being asked, also, we kind and try to
help your associates and your friends if they have, like, questions that you can address and you can
answer very accurately, since that's also kind of a good learning process when you try to explain it
to someone else.
And yeah, this is it for these Medio guys.
My name is Vlad.
This is Alphatech.
I hope you like the course so far and until next time, I'll see you then.
Oh, and by the way, don't forget to let me know what you think of the video and maybe to leave some
review that I will know that the process is going exactly as planned.
Or at least I hope so.
Yeah.
Bye bye.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.