1 00:00:01,470 --> 00:00:02,370 Hi, everyone. 2 00:00:02,400 --> 00:00:07,930 So in this video, we are going to write the court for this problem and let's start writing the code. 3 00:00:08,070 --> 00:00:09,830 I have already explained you everything. 4 00:00:09,870 --> 00:00:13,120 So now the only thing remaining is to just start writing the code. 5 00:00:13,140 --> 00:00:16,620 So, first of all, we should change the name to in order. 6 00:00:16,890 --> 00:00:17,200 Right. 7 00:00:17,260 --> 00:00:19,590 We are given in order areas input. 8 00:00:20,040 --> 00:00:24,270 And let's discuss the recursive relation once again and let's write it somewhere. 9 00:00:25,080 --> 00:00:26,280 So we discuss that. 10 00:00:26,610 --> 00:00:34,320 First of all, we will find out the maximum element in the area and obviously the index for this and 11 00:00:34,320 --> 00:00:36,530 let's call it mixed index. 12 00:00:37,200 --> 00:00:39,630 We will find out the maximum element and the mix index. 13 00:00:39,900 --> 00:00:44,240 So what we'll do after finding out the maximum element, this will be my root node. 14 00:00:45,930 --> 00:00:48,660 This will be my node for calling on left. 15 00:00:48,810 --> 00:00:52,110 I will pass this index and I will pass. 16 00:00:53,130 --> 00:00:56,650 Max index minus one. 17 00:00:57,630 --> 00:01:04,890 So this is the START index, this is the end index and for calling on right, the START index will be 18 00:01:06,390 --> 00:01:10,970 mixed index plus one and an index and that's it. 19 00:01:12,360 --> 00:01:13,370 And that's third rate. 20 00:01:13,830 --> 00:01:15,850 So let's start writing the code. 21 00:01:15,870 --> 00:01:20,070 So first of all, let's check the size. 22 00:01:20,490 --> 00:01:28,920 So if the size of the area and the size of zero, that means the air is empty. 23 00:01:29,220 --> 00:01:32,310 So in this case, your tree will not exist so you can return null. 24 00:01:33,570 --> 00:01:37,980 Otherwise, what I'm going to do is write a function helper. 25 00:01:38,430 --> 00:01:41,400 So what this helper function does, it creates three. 26 00:01:42,030 --> 00:01:49,170 And I need to pass the in order that I will pass the starting, which is zero starting index and I will 27 00:01:49,170 --> 00:01:54,480 pass the ADD index, which is in order that says minus one. 28 00:01:56,360 --> 00:02:02,420 Fine, this is the START index and this is the end index and this helper function, it will return the 29 00:02:02,810 --> 00:02:04,370 routine order of the Nutri. 30 00:02:05,240 --> 00:02:09,500 So what this helper function will return a dilettante root node. 31 00:02:09,560 --> 00:02:18,980 So it is a train or start helper function, what it is taking as input, it is taking in other areas 32 00:02:18,980 --> 00:02:22,790 input so you can take in order that is in port. 33 00:02:22,970 --> 00:02:23,750 What else. 34 00:02:23,780 --> 00:02:26,420 So it is taking the starting next. 35 00:02:26,750 --> 00:02:30,740 It is taking and index as input. 36 00:02:32,600 --> 00:02:34,580 So this is going to be a recursive function. 37 00:02:34,970 --> 00:02:38,400 So we know the recursive relation, but what will be the best case? 38 00:02:38,420 --> 00:02:39,830 So basically it is very simple. 39 00:02:39,830 --> 00:02:43,050 If START is good, then this is a start. 40 00:02:43,310 --> 00:02:45,560 So if start is good, then end. 41 00:02:46,820 --> 00:02:49,430 It started as guerdon, and that means they're done. 42 00:02:51,550 --> 00:02:54,030 We will return null now. 43 00:02:54,040 --> 00:02:56,520 What we need to do, so what was the first step? 44 00:02:56,530 --> 00:03:04,600 First step was basically we need to find out the maximum element, because that will be my route to 45 00:03:04,630 --> 00:03:11,950 find a maksym element, because that element is my route. 46 00:03:13,760 --> 00:03:19,410 So let's take one variable, let's say the maximum value, so what is the maximum value? 47 00:03:19,430 --> 00:03:26,160 This is in the minimum and obviously we need maximum indexed so that I can call on left and right. 48 00:03:27,830 --> 00:03:32,150 So let's take one more variable, which is maximum depth. 49 00:03:32,150 --> 00:03:34,380 And let's say initially this is minus one. 50 00:03:35,900 --> 00:03:36,860 Now we're trying to do. 51 00:03:37,790 --> 00:03:40,980 We need to iterate over the area to find out the maximum element. 52 00:03:41,030 --> 00:03:48,320 So I will start from starting index I list in articles two and index I placeless. 53 00:03:50,480 --> 00:03:52,670 So if the current element. 54 00:03:56,360 --> 00:04:07,370 Is greater than the maximum value, then we are going to update the maximum value to this value and 55 00:04:07,370 --> 00:04:10,580 obviously we will update the maximum index. 56 00:04:10,910 --> 00:04:15,410 So Maksym indexes, I find. 57 00:04:16,670 --> 00:04:26,920 So now we know the maxim element so we can create root node, so let's create a root for the Soul Train 58 00:04:26,930 --> 00:04:35,270 Wildstar Root will be new right node and we need to give the data that is the maximum value. 59 00:04:36,680 --> 00:04:37,100 Fine. 60 00:04:37,840 --> 00:04:39,260 So now for this route. 61 00:04:40,080 --> 00:04:51,300 And to find out the left subtree for this and we need to find out the rights of this and after finding 62 00:04:51,300 --> 00:04:53,430 out these two values, we will return. 63 00:04:55,500 --> 00:04:57,010 So what will be left? 64 00:04:57,060 --> 00:04:58,050 We discussed that. 65 00:04:59,130 --> 00:05:02,970 What I need to do, I will call on left separately. 66 00:05:03,030 --> 00:05:05,010 So in order, it will remain same. 67 00:05:07,050 --> 00:05:15,170 Starting next will remain the same and what will be the end and will be the maximum index minus one, 68 00:05:17,250 --> 00:05:23,450 and for building the rights of Prevert, I will do the start. 69 00:05:23,460 --> 00:05:31,830 Index value will be the max index plus one and and index and the two guys that said, so what we are 70 00:05:31,830 --> 00:05:34,840 doing here, this is simple case, right? 71 00:05:35,190 --> 00:05:41,110 So our approach was, first of all, we need to find out the maximum element late because the traversal 72 00:05:41,130 --> 00:05:44,970 is left-to-right, the maximum element will be our root node. 73 00:05:45,660 --> 00:05:50,780 And obviously we need to find out the MAKSYM index so that I can call on left and right. 74 00:05:52,080 --> 00:05:54,230 So I am migrating from start to end. 75 00:05:54,600 --> 00:05:58,920 And if this data is greater than the maximum value, then you will update the maximum value and the 76 00:05:58,920 --> 00:06:01,710 maximum index, which is simple right now. 77 00:06:01,710 --> 00:06:07,520 What they are doing, since we know the maximum data, let's say the maximum value is five. 78 00:06:07,740 --> 00:06:10,370 So I'm creating a node with the data five. 79 00:06:10,380 --> 00:06:14,870 So we will create an order of data five and four, building the three. 80 00:06:14,940 --> 00:06:16,650 We need to build the left of the tree. 81 00:06:16,650 --> 00:06:18,230 We need to build right on the tree. 82 00:06:18,270 --> 00:06:23,940 So I am building left and building right for building left called the helper function for building right 83 00:06:23,940 --> 00:06:32,190 called the helper function and the end will be maksym index minus one and the start will be in this 84 00:06:32,190 --> 00:06:34,230 case maksym index plus one. 85 00:06:34,230 --> 00:06:36,140 And that's a very simple code. 86 00:06:36,480 --> 00:06:39,690 So let's try to run our code first. 87 00:06:39,690 --> 00:06:43,440 We will test against the basic test cases, then we will submit. 88 00:06:47,180 --> 00:06:52,160 OK, so the spelling mistake, this will not be try this is actually three. 89 00:06:57,370 --> 00:06:58,960 Yep, so let's admit now. 90 00:07:04,300 --> 00:07:06,660 So our goal is working, right? 91 00:07:07,360 --> 00:07:08,980 This was very simple called. 92 00:07:10,100 --> 00:07:13,490 Only this much amount of gold, so this was really, really very simple. 93 00:07:14,210 --> 00:07:18,410 So this is all about this video, guys, I will see you in the next one. 94 00:07:18,590 --> 00:07:19,130 Thank you.