1 00:00:00,660 --> 00:00:01,450 Hi, everyone. 2 00:00:01,470 --> 00:00:05,490 So in this video, we are going to solve this question, machsom Adolf Island. 3 00:00:06,640 --> 00:00:13,540 So the question is basically, we are given a two day grid and cross and binary metrics and one represent 4 00:00:13,540 --> 00:00:18,280 land and zero represent water, and we can move in four directions, right. 5 00:00:18,280 --> 00:00:19,540 Horizontally and vertically. 6 00:00:19,810 --> 00:00:22,640 So in total, we can move in four directions. 7 00:00:23,050 --> 00:00:26,410 So this matrix is basically containing all four zeros and ones. 8 00:00:26,710 --> 00:00:29,820 We need to find out the maximum area of island in the grid. 9 00:00:30,100 --> 00:00:37,390 And if there is no island, that means if the mattocks contain only zero that is only water, then my 10 00:00:37,420 --> 00:00:38,430 answer will be zero. 11 00:00:38,890 --> 00:00:39,150 Right. 12 00:00:39,400 --> 00:00:43,510 So let's see this example and let's try to find out what will be the answer for this. 13 00:00:45,670 --> 00:00:48,760 So this is our binary grid. 14 00:00:48,790 --> 00:00:51,670 Yes, so let's see what will be our answer. 15 00:00:51,910 --> 00:00:56,950 So since this is water, right, sorry, this is land, so area is one. 16 00:00:57,190 --> 00:00:59,530 In this case, the area is four. 17 00:01:00,670 --> 00:01:02,740 So here we have area five. 18 00:01:04,180 --> 00:01:05,860 We have area four. 19 00:01:05,860 --> 00:01:14,410 Here we have area five here and we have area six here, eight. 20 00:01:14,780 --> 00:01:16,630 So this is the maximum area. 21 00:01:17,110 --> 00:01:19,000 This is the maximum area six. 22 00:01:19,270 --> 00:01:21,340 And that's why the output is six. 23 00:01:21,610 --> 00:01:26,010 And they are explaining the caution in the explanation that the answer will not be eleven. 24 00:01:26,020 --> 00:01:30,990 So how come the answer will be 11 a.m. will be 11 if I can move in diagonal direction also. 25 00:01:31,000 --> 00:01:37,360 So if I'm allowed to move in diagonal direction, that my answer will be 11 because this sixth and we 26 00:01:37,360 --> 00:01:38,170 have five here. 27 00:01:39,150 --> 00:01:39,550 Right. 28 00:01:39,720 --> 00:01:45,390 So six and five, they will be connected if I can move diagonally, so that's why they are writing that 29 00:01:45,390 --> 00:01:49,020 down seven, not 11, because we cannot move diagonally. 30 00:01:49,300 --> 00:01:52,770 We can move directionally either horizontally or vertically. 31 00:01:53,930 --> 00:01:55,160 The answer will be six. 32 00:01:57,090 --> 00:01:59,570 So how can we solve this question? 33 00:02:01,050 --> 00:02:07,380 So if you remember in previous videos, we have learned that question number of aliens and in that question 34 00:02:07,380 --> 00:02:08,750 we they're very similar. 35 00:02:09,180 --> 00:02:11,090 This all very similar question to this. 36 00:02:11,400 --> 00:02:18,750 So what we did was we need to find out the number of connected components in previous question. 37 00:02:19,440 --> 00:02:19,830 Right. 38 00:02:20,170 --> 00:02:24,150 We need to find out the number of connected components and previous question and for finding out the 39 00:02:24,150 --> 00:02:26,530 number of connected components of a user DFS. 40 00:02:27,690 --> 00:02:31,710 So here what I'm doing, I am finding out the number of connected components. 41 00:02:31,710 --> 00:02:36,390 Eight, I am ultimately finding out connected components. 42 00:02:36,720 --> 00:02:42,240 And while I am finding out connecting components, what I will do, I will maintain one count. 43 00:02:44,130 --> 00:02:46,590 I need to maintain one count that. 44 00:02:46,590 --> 00:02:51,490 What is the idea for the current matrix current connected component. 45 00:02:51,510 --> 00:02:51,890 Right. 46 00:02:52,740 --> 00:03:01,080 So I need to maintain one variable count or you can say I will maintain one variable area and that area 47 00:03:01,080 --> 00:03:03,430 will be the area of connected components. 48 00:03:03,690 --> 00:03:09,840 So while you are finding the connected component, just also find the area along with it and we will 49 00:03:09,840 --> 00:03:17,090 find out the area for all connected component, find out the area for all connected components. 50 00:03:17,700 --> 00:03:21,380 And our answer will be the mixture of all these areas. 51 00:03:22,170 --> 00:03:24,710 We will take maximum of all the areas. 52 00:03:24,720 --> 00:03:25,120 Right. 53 00:03:25,470 --> 00:03:28,340 So let me try to explain you again. 54 00:03:28,350 --> 00:03:30,780 So what I am trying to say here is what I will do. 55 00:03:31,620 --> 00:03:33,630 I will find out the connected component. 56 00:03:35,130 --> 00:03:35,410 Right. 57 00:03:35,520 --> 00:03:38,640 So first step is find the number of connected components. 58 00:03:40,560 --> 00:03:46,950 So when you are finding out the number of connected components, you will also find out that sadiya 59 00:03:47,460 --> 00:03:47,820 rate. 60 00:03:48,030 --> 00:03:48,840 So we'll find out. 61 00:03:48,840 --> 00:03:52,510 The area for this is for the area for this is six. 62 00:03:52,770 --> 00:03:58,590 The area for this is five area for this five area for this is for area for this one. 63 00:03:59,160 --> 00:04:03,720 So while finding out the number of connected components, we will find out the area for each connected 64 00:04:03,720 --> 00:04:08,370 component and we will take maximum of all make sense of all the areas. 65 00:04:08,370 --> 00:04:08,760 Right. 66 00:04:08,970 --> 00:04:10,390 And that will be our answer. 67 00:04:11,700 --> 00:04:16,380 Now, the question is how we can find out a number of connected components that we have already covered 68 00:04:16,380 --> 00:04:21,390 in our last we're doing our last program, which was number of aliens using the algorithm. 69 00:04:21,750 --> 00:04:24,270 You can go to each and every connected component. 70 00:04:24,690 --> 00:04:25,060 Right. 71 00:04:25,770 --> 00:04:31,600 So what we need to do, you just need to modify our previous code, right. 72 00:04:31,860 --> 00:04:38,050 You just need to modify our previous code to maintain area and then take the maximum of all the areas. 73 00:04:39,090 --> 00:04:42,570 So what you need to do, you need to modify this code. 74 00:04:43,920 --> 00:04:48,060 So we have covered this problem in our last videos, in our previous videos. 75 00:04:48,300 --> 00:04:50,310 So we just need to modify this code. 76 00:04:50,790 --> 00:04:55,810 You need to maintain one variable area and you will take the maximum of all the areas. 77 00:04:56,370 --> 00:04:58,370 So that is the thing that you need to do, right? 78 00:04:58,950 --> 00:05:04,590 I highly recommend that you try according this problem, what data do you just need to modify this code? 79 00:05:05,430 --> 00:05:06,690 There's nothing much. 80 00:05:07,830 --> 00:05:13,250 You just need to add a few variables, maintain the area and take the mix of all the areas. 81 00:05:14,400 --> 00:05:20,850 So I highly recommend that you try coding this problem and you can definitely was the solution in the 82 00:05:20,850 --> 00:05:21,540 next video. 83 00:05:21,600 --> 00:05:23,990 So we will be writing the code for this problem. 84 00:05:24,390 --> 00:05:29,310 Basically, we will be modifying the code for the number of aliens problem in our next video so that 85 00:05:29,310 --> 00:05:31,410 that will work for some audio files. 86 00:05:31,410 --> 00:05:34,470 And also so this is all about this device. 87 00:05:34,470 --> 00:05:35,890 I will see you in the next one. 88 00:05:35,910 --> 00:05:36,480 Thank you.