Hi, everyone, welcome back.
So in this video, we are going to discuss about discussion, distinct, no innuendo.
So let's try to read the problem statement and let's try to analyze what is the problem and what can
be the possible solution.
The input will contain two things.
First is basically, Neddie, and second thing, basically, Brindusa is.
Second is basically windows size, so window size is three, that means consider three elements one,
two and one.
Now, what other windows can be possible?
So remove one now and add this tree so another window can be two and three.
Now, remove these two and add this four.
So now the window will become one, three, four.
So you can see window sizes three.
So that's why I have three elements.
Now, I will remove this element and I will add this element.
So now the window is three for entry.
So these are the possible windows.
So these are all possible windows.
Offices three, offices three now after figuring out all the possible windows what to do, you need
to find out how many unique elements are there.
So in this case, two unique elements.
Are there one or two in this window?
I have three unique elements.
One to entry in this window.
I have three unique elements, one, three and four.
And in this window I have two unique elements.
So what will be my output?
My output will be the collection of all these.
So my output will be two, three, three and two.
So this will be my output for input one.
So let's try to see what is the output for and what, when and where is the output.
Yes, so this is two, three, three and two.
And that is what we are done here, two, three, three and two.
So I hope you have the question.
If not, let's try again now.
This time.
Do with me rate.
So what do you do?
Window size is three.
OK, so that means consider the first three elements.
So consider the first three elements and this will be my window.
Now what I will do.
So remove this element and we need to maintain the size three.
So I will add this element.
Now, this is my next window.
Which is two, one and three now, again, remove this element and take this element, so this will
be my new window, one, three and four.
Now, again, remove this element and consider this element, so this will be my new window, that will
be three, four and three.
So now I hope you know, what are all the possible windows of Sastry?
And after figuring out all the windows, what do you need to find out the number of unique elements?
So how many unique elements we have here to how many unique elements?
Three.
How many elements?
Three, how many unique elements.
So this will be my answer to three.
Three, two.
Now, let's talk about this example.
So window size is one to consider, one element.
Now, remove this element and add a new element.
So, again, window size is one, so remove this element, add this element.
So again, window size is one, so only one element.
So remove this element.
Add this element.
So since the window size is one, so that's why.
The number of elements in the window will be one and how many unique elements will be there since the
window is containing only one element.
So the number of unique element will always be one.
So this will be my answer for this input.
And we can see that the answer for our photo is one one, one one.
So now you have understood the question properly.
Now let's discuss how we can solve this question.
So this is very simple and very easy.
So what do will do?
I will maintain one map.
And this is my answer.
Answer at a rate we need to return when Eddie, we can see we need to return one Eddie now Inmet But
I will do the developer will be the key will be basically the element and the value will be the count
of that element in window of size.
W rate.
Window size is three.
So let's see how we can solve this problem.
So what do you do?
First of all, the window sizes, three cents, window sizes three to one.
So what I will do, I will insert one in the map and each count this one.
So first of all, I need to consider this window, right, because the window sizes three.
So I am considering three elements.
Now, the next is elemental.
So insert element in the map.
And what is the count?
Count is when now the next element is when one is already present in the map.
So we will update its count and now the count of one is two and that we will stop here because we need
to consider only three elements.
We will stop here and we will do so in MAP.
How many elements are there?
Two elements are present.
Two entries are there in the map.
So my answer will be to write.
What is to do is basically map out size.
The number of entries in the map.
Fine.
Very good.
Now, let's start now what I need to do, I will consider one more element.
So let me raise this first.
So what do we do, we have considered these three elements.
Now I will consider this element.
So ultimately what I will do elementary is not present in the map, so I will insert and its count is
one.
So now the window size has become four, but window has to be of size three.
So we will delete the last element.
So what I will do, I will go to the map and what I will do, I will reduce its count by one.
I am removing one right.
I am removing one so each count will reduce by one.
So this is the new count for one.
And what need to do.
We are considering this window.
So how many elements are there?
Again, my size and my map glasses will give you three because there are three elements.
Now let's move forward again.
So what I will do now, I will consider this element.
So I will insert this element in the map and it's counted one, but now we have considered the four
elements, but the window sizes three.
So I will remove this element from the map.
So remove two.
So I'm removing two.
So the count will decrease by one.
So the count will become zero.
And since the count is zero, that means we need to remove this entry from the map.
We need to remove this entity from the map because the count becomes zero.
And now for this window, how many elements are there?
How many elements are there?
That is my map.
Size and map is containing three entries.
So three.
Now it will consider the last element registry, so I will insert old trees already present, so I will
increase its count by one so the count becomes two and we need to remove element one.
So I will go to eliminate one and I will reduce its count to zero.
And since the count becomes zero, that means you need to remove this element from the map.
You will remove this element from the map.
And how many distinct elements are there.
So my map daudzai, that will give you two because two elements are present in the map and that is your
answer.
You will reach here and it will stop.
You are trading already at right.
And you will reach the end of the area.
So you will stop.
And this is your answer to three, three, two, which is the right answer.
Perfect.
Now let's talk about this.
So this is our map and let's quickly so we know size is one, so I am standing here, I will insert
this element in the map.
So the counties one and this is my answer, Victor.
Answer.
Eddie, what is my map that says it is containing one element?
So that's why one map is containing one entity.
So one next element is one.
So I will increase its count.
It's going to become two.
But you need to remove this element so its count will decrease again.
So the count again becomes one now for finding out the number of unique elements.
The number of entries in the map is one.
So that's why the output is one.
Now, I will continue this element two, so I will insert two and the count is one.
But I need to remove this element.
So the count is one.
I will decrease its count by one to the count become zero and zero means remove.
So I will remove it.
And the number of unique elements is basically the number of countries in the map and no fantasias,
only one.
So that's why one.
Now, again, I will consider this element to so I will increase its count.
Byron, so the count becomes two, but I need to remove this element so the government will become one
again, and how many unique elements are there?
So maybe containing only one, and that's why the output is one.
And finally, you will reach the end of the year end.
You will stop.
And this is your answer.
One one, one one.
Which is correct.
So I hope you have understood the question very well and the solution also very well.
And the part is also going to be very, very simple.
So what do you need to do?
You need to maintain one map map of element and count.
And what does discount discount this discount of the element in window size, the blue gentlemen in
NSW and my map that says both sides will give you the number of unique elements, will give you the
number of entries in the map and you need to maintain this on Saturday because we need to return one
at a.
Simple, so the cold is going to be very, very simple and you can all caused this problem very easily.
So we'll be writing the code for this problem in the next video.
And I will say you did.
Thank you.