Hi, everyone.
So in this video, we are going to solve this question, machsom Adolf Island.
So the question is basically, we are given a two day grid and cross and binary metrics and one represent
land and zero represent water, and we can move in four directions, right.
Horizontally and vertically.
So in total, we can move in four directions.
So this matrix is basically containing all four zeros and ones.
We need to find out the maximum area of island in the grid.
And if there is no island, that means if the mattocks contain only zero that is only water, then my
answer will be zero.
Right.
So let's see this example and let's try to find out what will be the answer for this.
So this is our binary grid.
Yes, so let's see what will be our answer.
So since this is water, right, sorry, this is land, so area is one.
In this case, the area is four.
So here we have area five.
We have area four.
Here we have area five here and we have area six here, eight.
So this is the maximum area.
This is the maximum area six.
And that's why the output is six.
And they are explaining the caution in the explanation that the answer will not be eleven.
So how come the answer will be 11 a.m. will be 11 if I can move in diagonal direction also.
So if I'm allowed to move in diagonal direction, that my answer will be 11 because this sixth and we
have five here.
Right.
So six and five, they will be connected if I can move diagonally, so that's why they are writing that
down seven, not 11, because we cannot move diagonally.
We can move directionally either horizontally or vertically.
The answer will be six.
So how can we solve this question?
So if you remember in previous videos, we have learned that question number of aliens and in that question
we they're very similar.
This all very similar question to this.
So what we did was we need to find out the number of connected components in previous question.
Right.
We need to find out the number of connected components and previous question and for finding out the
number of connected components of a user DFS.
So here what I'm doing, I am finding out the number of connected components.
Eight, I am ultimately finding out connected components.
And while I am finding out connecting components, what I will do, I will maintain one count.
I need to maintain one count that.
What is the idea for the current matrix current connected component.
Right.
So I need to maintain one variable count or you can say I will maintain one variable area and that area
will be the area of connected components.
So while you are finding the connected component, just also find the area along with it and we will
find out the area for all connected component, find out the area for all connected components.
And our answer will be the mixture of all these areas.
We will take maximum of all the areas.
Right.
So let me try to explain you again.
So what I am trying to say here is what I will do.
I will find out the connected component.
Right.
So first step is find the number of connected components.
So when you are finding out the number of connected components, you will also find out that sadiya
rate.
So we'll find out.
The area for this is for the area for this is six.
The area for this is five area for this five area for this is for area for this one.
So while finding out the number of connected components, we will find out the area for each connected
component and we will take maximum of all make sense of all the areas.
Right.
And that will be our answer.
Now, the question is how we can find out a number of connected components that we have already covered
in our last we're doing our last program, which was number of aliens using the algorithm.
You can go to each and every connected component.
Right.
So what we need to do, you just need to modify our previous code, right.
You just need to modify our previous code to maintain area and then take the maximum of all the areas.
So what you need to do, you need to modify this code.
So we have covered this problem in our last videos, in our previous videos.
So we just need to modify this code.
You need to maintain one variable area and you will take the maximum of all the areas.
So that is the thing that you need to do, right?
I highly recommend that you try according this problem, what data do you just need to modify this code?
There's nothing much.
You just need to add a few variables, maintain the area and take the mix of all the areas.
So I highly recommend that you try coding this problem and you can definitely was the solution in the
next video.
So we will be writing the code for this problem.
Basically, we will be modifying the code for the number of aliens problem in our next video so that
that will work for some audio files.
And also so this is all about this device.
I will see you in the next one.
Thank you.