1 00:00:00,810 --> 00:00:02,370 Hi, everyone, welcome back. 2 00:00:02,400 --> 00:00:07,820 So in this video, we are going to discuss about discussion, distinct, no innuendo. 3 00:00:08,520 --> 00:00:14,280 So let's try to read the problem statement and let's try to analyze what is the problem and what can 4 00:00:14,280 --> 00:00:15,450 be the possible solution. 5 00:00:16,600 --> 00:00:18,660 The input will contain two things. 6 00:00:18,660 --> 00:00:23,240 First is basically, Neddie, and second thing, basically, Brindusa is. 7 00:00:26,040 --> 00:00:33,720 Second is basically windows size, so window size is three, that means consider three elements one, 8 00:00:33,720 --> 00:00:34,490 two and one. 9 00:00:34,590 --> 00:00:36,600 Now, what other windows can be possible? 10 00:00:36,760 --> 00:00:42,530 So remove one now and add this tree so another window can be two and three. 11 00:00:43,740 --> 00:00:46,980 Now, remove these two and add this four. 12 00:00:47,700 --> 00:00:50,090 So now the window will become one, three, four. 13 00:00:50,100 --> 00:00:52,230 So you can see window sizes three. 14 00:00:52,230 --> 00:00:54,180 So that's why I have three elements. 15 00:00:56,750 --> 00:01:00,900 Now, I will remove this element and I will add this element. 16 00:01:01,400 --> 00:01:04,209 So now the window is three for entry. 17 00:01:04,519 --> 00:01:06,570 So these are the possible windows. 18 00:01:06,680 --> 00:01:09,050 So these are all possible windows. 19 00:01:11,740 --> 00:01:19,510 Offices three, offices three now after figuring out all the possible windows what to do, you need 20 00:01:19,540 --> 00:01:21,720 to find out how many unique elements are there. 21 00:01:22,030 --> 00:01:24,790 So in this case, two unique elements. 22 00:01:24,790 --> 00:01:27,080 Are there one or two in this window? 23 00:01:27,400 --> 00:01:29,080 I have three unique elements. 24 00:01:29,080 --> 00:01:31,320 One to entry in this window. 25 00:01:31,330 --> 00:01:34,110 I have three unique elements, one, three and four. 26 00:01:34,420 --> 00:01:38,130 And in this window I have two unique elements. 27 00:01:39,340 --> 00:01:40,690 So what will be my output? 28 00:01:41,230 --> 00:01:44,650 My output will be the collection of all these. 29 00:01:45,010 --> 00:01:49,720 So my output will be two, three, three and two. 30 00:01:49,990 --> 00:01:53,160 So this will be my output for input one. 31 00:01:53,830 --> 00:02:00,970 So let's try to see what is the output for and what, when and where is the output. 32 00:02:01,140 --> 00:02:04,840 Yes, so this is two, three, three and two. 33 00:02:04,840 --> 00:02:08,860 And that is what we are done here, two, three, three and two. 34 00:02:09,009 --> 00:02:10,780 So I hope you have the question. 35 00:02:11,170 --> 00:02:14,320 If not, let's try again now. 36 00:02:14,320 --> 00:02:14,860 This time. 37 00:02:15,160 --> 00:02:16,720 Do with me rate. 38 00:02:17,050 --> 00:02:17,980 So what do you do? 39 00:02:19,960 --> 00:02:21,400 Window size is three. 40 00:02:21,850 --> 00:02:25,460 OK, so that means consider the first three elements. 41 00:02:26,680 --> 00:02:29,710 So consider the first three elements and this will be my window. 42 00:02:30,670 --> 00:02:31,510 Now what I will do. 43 00:02:31,870 --> 00:02:35,760 So remove this element and we need to maintain the size three. 44 00:02:35,770 --> 00:02:37,210 So I will add this element. 45 00:02:37,240 --> 00:02:38,680 Now, this is my next window. 46 00:02:40,100 --> 00:02:48,290 Which is two, one and three now, again, remove this element and take this element, so this will 47 00:02:48,290 --> 00:02:51,680 be my new window, one, three and four. 48 00:02:53,670 --> 00:03:01,140 Now, again, remove this element and consider this element, so this will be my new window, that will 49 00:03:01,140 --> 00:03:03,230 be three, four and three. 50 00:03:03,420 --> 00:03:08,220 So now I hope you know, what are all the possible windows of Sastry? 51 00:03:08,490 --> 00:03:13,940 And after figuring out all the windows, what do you need to find out the number of unique elements? 52 00:03:13,980 --> 00:03:18,110 So how many unique elements we have here to how many unique elements? 53 00:03:18,120 --> 00:03:18,450 Three. 54 00:03:18,450 --> 00:03:19,650 How many elements? 55 00:03:19,650 --> 00:03:21,900 Three, how many unique elements. 56 00:03:22,440 --> 00:03:25,860 So this will be my answer to three. 57 00:03:25,860 --> 00:03:26,340 Three, two. 58 00:03:27,460 --> 00:03:29,980 Now, let's talk about this example. 59 00:03:31,530 --> 00:03:34,230 So window size is one to consider, one element. 60 00:03:35,900 --> 00:03:38,670 Now, remove this element and add a new element. 61 00:03:38,960 --> 00:03:43,560 So, again, window size is one, so remove this element, add this element. 62 00:03:43,580 --> 00:03:46,450 So again, window size is one, so only one element. 63 00:03:46,820 --> 00:03:47,900 So remove this element. 64 00:03:47,900 --> 00:03:48,720 Add this element. 65 00:03:49,160 --> 00:03:53,210 So since the window size is one, so that's why. 66 00:03:55,390 --> 00:04:00,880 The number of elements in the window will be one and how many unique elements will be there since the 67 00:04:00,880 --> 00:04:02,740 window is containing only one element. 68 00:04:03,160 --> 00:04:05,750 So the number of unique element will always be one. 69 00:04:05,980 --> 00:04:09,340 So this will be my answer for this input. 70 00:04:09,820 --> 00:04:14,120 And we can see that the answer for our photo is one one, one one. 71 00:04:16,240 --> 00:04:19,029 So now you have understood the question properly. 72 00:04:19,450 --> 00:04:21,690 Now let's discuss how we can solve this question. 73 00:04:22,000 --> 00:04:24,500 So this is very simple and very easy. 74 00:04:25,330 --> 00:04:26,130 So what do will do? 75 00:04:26,470 --> 00:04:27,850 I will maintain one map. 76 00:04:30,310 --> 00:04:32,110 And this is my answer. 77 00:04:33,850 --> 00:04:40,830 Answer at a rate we need to return when Eddie, we can see we need to return one Eddie now Inmet But 78 00:04:40,830 --> 00:04:47,760 I will do the developer will be the key will be basically the element and the value will be the count 79 00:04:47,760 --> 00:04:51,090 of that element in window of size. 80 00:04:51,090 --> 00:04:52,980 W rate. 81 00:04:52,980 --> 00:04:54,000 Window size is three. 82 00:04:55,820 --> 00:04:58,790 So let's see how we can solve this problem. 83 00:04:58,820 --> 00:04:59,560 So what do you do? 84 00:05:00,500 --> 00:05:05,820 First of all, the window sizes, three cents, window sizes three to one. 85 00:05:05,840 --> 00:05:10,220 So what I will do, I will insert one in the map and each count this one. 86 00:05:10,670 --> 00:05:14,330 So first of all, I need to consider this window, right, because the window sizes three. 87 00:05:14,330 --> 00:05:15,950 So I am considering three elements. 88 00:05:16,520 --> 00:05:18,210 Now, the next is elemental. 89 00:05:18,590 --> 00:05:20,570 So insert element in the map. 90 00:05:20,570 --> 00:05:22,470 And what is the count? 91 00:05:22,500 --> 00:05:28,700 Count is when now the next element is when one is already present in the map. 92 00:05:28,730 --> 00:05:36,680 So we will update its count and now the count of one is two and that we will stop here because we need 93 00:05:36,680 --> 00:05:38,080 to consider only three elements. 94 00:05:38,100 --> 00:05:42,170 We will stop here and we will do so in MAP. 95 00:05:42,170 --> 00:05:43,520 How many elements are there? 96 00:05:43,640 --> 00:05:44,870 Two elements are present. 97 00:05:44,870 --> 00:05:46,330 Two entries are there in the map. 98 00:05:46,760 --> 00:05:49,760 So my answer will be to write. 99 00:05:49,760 --> 00:05:52,370 What is to do is basically map out size. 100 00:05:53,530 --> 00:05:56,260 The number of entries in the map. 101 00:05:57,370 --> 00:05:57,800 Fine. 102 00:05:59,110 --> 00:05:59,620 Very good. 103 00:05:59,650 --> 00:06:04,800 Now, let's start now what I need to do, I will consider one more element. 104 00:06:04,960 --> 00:06:06,580 So let me raise this first. 105 00:06:09,530 --> 00:06:13,410 So what do we do, we have considered these three elements. 106 00:06:14,000 --> 00:06:16,150 Now I will consider this element. 107 00:06:16,760 --> 00:06:22,850 So ultimately what I will do elementary is not present in the map, so I will insert and its count is 108 00:06:22,850 --> 00:06:23,100 one. 109 00:06:23,510 --> 00:06:28,550 So now the window size has become four, but window has to be of size three. 110 00:06:28,560 --> 00:06:30,960 So we will delete the last element. 111 00:06:32,030 --> 00:06:38,030 So what I will do, I will go to the map and what I will do, I will reduce its count by one. 112 00:06:38,270 --> 00:06:39,570 I am removing one right. 113 00:06:39,950 --> 00:06:43,280 I am removing one so each count will reduce by one. 114 00:06:44,960 --> 00:06:46,910 So this is the new count for one. 115 00:06:47,210 --> 00:06:48,340 And what need to do. 116 00:06:48,350 --> 00:06:49,890 We are considering this window. 117 00:06:50,480 --> 00:06:52,130 So how many elements are there? 118 00:06:52,130 --> 00:06:57,830 Again, my size and my map glasses will give you three because there are three elements. 119 00:06:58,520 --> 00:07:00,100 Now let's move forward again. 120 00:07:00,110 --> 00:07:02,600 So what I will do now, I will consider this element. 121 00:07:04,380 --> 00:07:11,100 So I will insert this element in the map and it's counted one, but now we have considered the four 122 00:07:11,100 --> 00:07:12,870 elements, but the window sizes three. 123 00:07:12,870 --> 00:07:14,970 So I will remove this element from the map. 124 00:07:15,360 --> 00:07:16,220 So remove two. 125 00:07:16,830 --> 00:07:17,980 So I'm removing two. 126 00:07:18,000 --> 00:07:19,910 So the count will decrease by one. 127 00:07:19,920 --> 00:07:21,460 So the count will become zero. 128 00:07:21,960 --> 00:07:28,380 And since the count is zero, that means we need to remove this entry from the map. 129 00:07:29,910 --> 00:07:33,620 We need to remove this entity from the map because the count becomes zero. 130 00:07:34,710 --> 00:07:40,710 And now for this window, how many elements are there? 131 00:07:40,830 --> 00:07:42,180 How many elements are there? 132 00:07:42,360 --> 00:07:43,820 That is my map. 133 00:07:44,080 --> 00:07:46,940 Size and map is containing three entries. 134 00:07:46,950 --> 00:07:47,580 So three. 135 00:07:50,470 --> 00:07:56,710 Now it will consider the last element registry, so I will insert old trees already present, so I will 136 00:07:56,710 --> 00:08:02,680 increase its count by one so the count becomes two and we need to remove element one. 137 00:08:04,000 --> 00:08:08,160 So I will go to eliminate one and I will reduce its count to zero. 138 00:08:08,860 --> 00:08:16,060 And since the count becomes zero, that means you need to remove this element from the map. 139 00:08:17,200 --> 00:08:19,300 You will remove this element from the map. 140 00:08:19,660 --> 00:08:21,980 And how many distinct elements are there. 141 00:08:22,330 --> 00:08:28,510 So my map daudzai, that will give you two because two elements are present in the map and that is your 142 00:08:28,510 --> 00:08:28,950 answer. 143 00:08:29,230 --> 00:08:31,900 You will reach here and it will stop. 144 00:08:32,990 --> 00:08:34,690 You are trading already at right. 145 00:08:34,809 --> 00:08:36,520 And you will reach the end of the area. 146 00:08:36,520 --> 00:08:37,299 So you will stop. 147 00:08:37,309 --> 00:08:40,690 And this is your answer to three, three, two, which is the right answer. 148 00:08:40,960 --> 00:08:41,440 Perfect. 149 00:08:41,679 --> 00:08:43,120 Now let's talk about this. 150 00:08:44,790 --> 00:08:52,620 So this is our map and let's quickly so we know size is one, so I am standing here, I will insert 151 00:08:52,620 --> 00:08:53,760 this element in the map. 152 00:08:54,000 --> 00:08:58,150 So the counties one and this is my answer, Victor. 153 00:08:58,170 --> 00:08:58,570 Answer. 154 00:08:58,680 --> 00:09:02,250 Eddie, what is my map that says it is containing one element? 155 00:09:02,260 --> 00:09:05,320 So that's why one map is containing one entity. 156 00:09:05,340 --> 00:09:08,040 So one next element is one. 157 00:09:08,280 --> 00:09:10,590 So I will increase its count. 158 00:09:10,740 --> 00:09:12,060 It's going to become two. 159 00:09:12,300 --> 00:09:16,740 But you need to remove this element so its count will decrease again. 160 00:09:16,740 --> 00:09:21,540 So the count again becomes one now for finding out the number of unique elements. 161 00:09:21,540 --> 00:09:23,220 The number of entries in the map is one. 162 00:09:23,220 --> 00:09:24,700 So that's why the output is one. 163 00:09:25,110 --> 00:09:29,010 Now, I will continue this element two, so I will insert two and the count is one. 164 00:09:29,220 --> 00:09:31,020 But I need to remove this element. 165 00:09:31,350 --> 00:09:32,430 So the count is one. 166 00:09:32,700 --> 00:09:36,890 I will decrease its count by one to the count become zero and zero means remove. 167 00:09:37,230 --> 00:09:38,910 So I will remove it. 168 00:09:39,150 --> 00:09:43,650 And the number of unique elements is basically the number of countries in the map and no fantasias, 169 00:09:43,650 --> 00:09:44,220 only one. 170 00:09:44,920 --> 00:09:45,780 So that's why one. 171 00:09:46,790 --> 00:09:50,750 Now, again, I will consider this element to so I will increase its count. 172 00:09:51,820 --> 00:09:57,100 Byron, so the count becomes two, but I need to remove this element so the government will become one 173 00:09:57,100 --> 00:10:00,220 again, and how many unique elements are there? 174 00:10:00,220 --> 00:10:03,170 So maybe containing only one, and that's why the output is one. 175 00:10:03,400 --> 00:10:05,590 And finally, you will reach the end of the year end. 176 00:10:05,590 --> 00:10:06,130 You will stop. 177 00:10:06,130 --> 00:10:07,140 And this is your answer. 178 00:10:07,720 --> 00:10:08,620 One one, one one. 179 00:10:08,620 --> 00:10:09,540 Which is correct. 180 00:10:09,550 --> 00:10:13,720 So I hope you have understood the question very well and the solution also very well. 181 00:10:14,110 --> 00:10:17,150 And the part is also going to be very, very simple. 182 00:10:17,680 --> 00:10:18,640 So what do you need to do? 183 00:10:18,820 --> 00:10:23,890 You need to maintain one map map of element and count. 184 00:10:24,950 --> 00:10:31,250 And what does discount discount this discount of the element in window size, the blue gentlemen in 185 00:10:31,270 --> 00:10:37,730 NSW and my map that says both sides will give you the number of unique elements, will give you the 186 00:10:37,730 --> 00:10:43,070 number of entries in the map and you need to maintain this on Saturday because we need to return one 187 00:10:43,070 --> 00:10:43,400 at a. 188 00:10:44,630 --> 00:10:49,910 Simple, so the cold is going to be very, very simple and you can all caused this problem very easily. 189 00:10:50,510 --> 00:10:53,460 So we'll be writing the code for this problem in the next video. 190 00:10:53,480 --> 00:10:54,680 And I will say you did. 191 00:10:54,860 --> 00:10:55,430 Thank you.