Hi, everyone.
So today we are going to solve this question, set metrics, zeros.
OK, so what is the question?
So question is very simple.
So basically our input will basically be Emmental and mattocks.
OK, so what we have to do so if there's a zero present, then we have to make an entire Roseto and
column zero.
OK, so for example, zero is here.
So what we'll do, we will make this entire column.
We will make this an entire roseto.
So basically our output will be zero zero zero and zero zero.
Everything else will remain Sim's or one one, one and one.
OK, now let's see this example.
So in this case, zero is present here.
So I will make this Rosero.
I will make this column zero.
OK, so what will be our output?
So will be zero zero zero and here it will be one.
OK, now let us consider this input.
OK, so in this input, zero is present here.
So what I will do, I will make this entire column zero.
I will make this and that.
Rosero.
So basically what will be an output?
So it is zero zero zero zero and zero and we have one one one and one, OK.
Now let us consider this input.
So in this input, zero is present here.
So I will make this and barrero zero, I will make this entire column zero.
OK, so zero is also present here.
So I will make this entire column zero.
I will make this entire I will make this an entire room zero.
So basically our output will be so zero zero zero zero zero zero zero zero.
And here we have four five three and one.
OK, so I hope you understood this question.
So this question is basically present only code.
OK, so this is the question.
We will be then but will basically be I in box.
And if an element is zero, but we have to do we have to make an entire row, an entire column zero.
OK, so we have to do this question in place.
So what is the meaning of in place.
So in place means we have to change this input.
We have to change the given matrix.
OK, we do not need to create another matrix.
So let's say this matrix is a.
So basically we have to do changes in Matrix only.
OK, we don't have to create another Matrix B, so we have to change.
We have to do changes in Matrix only.
And the expected time and space complexity for solving this problem is basically.
So time is Ammann and the space complexities are different.
OK, so this is the expected time and space complexity for this question.
OK, so let's see how we can solve this question.
First, natality brute force approach, the naive approach.
OK, so let us consider an example.
And so let's take an example.
So we have zero, let's say, for one zero three two one five four zero seven and two.
OK, so let's say this is the input.
Now, let us discuss approach number one.
So naive approach.
So what we will do basically, we will store the column and the rule number where the zero element is
present.
OK, so I will store.
I have a vector.
OK, so let's rename it Vector of integers and let's name it are OK and we will have another vector.
It will store the column number of the zero element.
OK, so we will have two vectors.
OK, so first Vector will restore the rule number.
Second, that devils to the column number.
OK, so now let's say trade over the input input matrix.
So this is zero zero one zero two zero.
Column one, column two, column three.
OK, so zero is present here.
So inside the row I will still zero inside column I will store zero zero is basically the index.
OK, so zero to index and zero the index null for one and zero.
So again we have zero zero four zero zero zero zero zero is already there.
And for three if we want to go right.
One more time.
OK.
So basically what we can do, we can instead of creating a vector, we can create a set.
OK, so what is said means basically they will be unique elements.
So insert they will be unique elements.
Not only good will be there.
OK, so for here the number is three, so I will store three.
OK, so suppose I'm using that.
So since I'm using that I will store zero only one time.
So OK, so inside this set the properties you will have only unique elements.
OK.
So now let us consider two or three years, not zero, two is not zero, one is not zero, five is not
zero four, it is not zero.
So we have zero here.
So the rule is two.
So I will write to here and the column number is basically one, so I will write one.
OK, now let's move ahead.
So this is seven and this is.
OK, so now we have our rule and column separately.
OK, so now let us prepare our output.
So for preparing the output, what we will do so we will iterate over the metrics again.
OK, so we will light it.
So this is the first element.
So I have zero ROI zero and also zero zero zero and zero since the wrong number in Brazil.
Also I will write to zero here.
Now let's come to this element.
So column number one or number zero.
So Roy's present column is also present.
So I will write to zero here.
Now, let's come to this Element one so Roys zero columnist, so column is not present, but Roy's present
since Roy's present, I will write to zero here.
OK, welcome to the settlement.
So basically, rule number is zero and no history and both are present.
So I will write to zero.
OK, so now let's come to this Element Elementary.
So rule number one, so rule number one, not present now, caller number zero.
So since zero, president, I will write to zero.
So I have to so far to no one not present, no one present, since no one is present.
So I will write zero here.
OK, now let's move ahead.
So now let's come to this element, element number one, since element number one columnist to do is
not present number one when it's not present.
So I will write one here.
No changes.
I will not make it zero.
OK, now let's come to this element five.
OK, so rule number one.
Rule number one is not present number three.
Yes.
Column number three is present.
So I will write to zero here.
OK, now let's come to this element.
So this is for rule number two.
Lesser number two is present.
So I will write to zero here.
Now, let's come to this element, this holiday zero so you can directly write zero.
This is a limited number seven, rule number two.
So, yes, we have rule number two.
So I will write to zero here.
So we have element to so Roland Burris to I will write zero here.
OK, so this is basically my output.
This will be the output.
OK, so what is the time and the space complexities or time complexities?
And I think we are just starting with the Matrix two times.
So Emman and the space complexities basically for creating this toolset, let's say the space complexities
and blessin OK.
So if you want to check your solution where the solution is wrong, let us verify our solution.
So what will happen now since this is zero?
I will make this entire column zero and I will make this an entire Rosero.
Since I have zero here, I will make this entire column zero.
I will make this entire rule zero since I have zero here.
So I will make this entire column zero and I will make this entire Rosero.
So basically I have zero everywhere.
Only this element will be there.
OK, so I will have only this element, one dressed.
Every element will be zero.
OK, so our solution, our naive approach is basically right.
OK, so this is the time and the space complexity for the naive approach.
But but as you can see, Yarbo, our solution is to solve this question in one space.
OK, we have to solve this question in open space so how we can solve this question in open space.
Let's see.
OK, so now let's discuss about our approach, the second, which is basically the efficient approach.
Efficient approach.
So in this efficient approach, what we will do, so we will make use of first reinforced column.
OK, so make use of first rule and first column.
OK, so let us take an example to understand this approach.
So basically, let's say I have one zero one one one, two, three, four and five.
OK, so this is basically my input.
Now we have to make use of first rule and first column.
OK, so our step number one is basically take two boolean variables.
OK, so take two Boolean variables.
Let's say their names are has zero first row and has zero first column.
OK, so initially both these variables are false.
OK, now let us update their values.
OK, so basically this is my first rule and this is my first column.
OK, so let's get rid of the first rule.
Yes, it is containing a zero element since it is containing a zero element.
So I will update the variable.
OK, now let's start with the first column.
It is not containing as irrelevant, so it will remain false.
It will remain false.
OK, now the second step, second step is basically you will read from the next one common starting
from one common one index.
You will iterate over the complete metrics.
And as soon as you encounter a zero element, so let's say I encounter element to zero at index Ikoma.
OK, so at index I see if I encounter as irrelevant what I will do.
So if I call my G is zero, then basically I will make I will make Ikoma zero zero and I will make zero
G zero.
OK, so what is the meaning of these two lines?
So let us see, so I would like to read from this element.
OK, let's make it zero.
OK, so this is one.
Do not do anything.
This is zero.
So as soon as I encounter a derailment, what I'm doing, I will go to the topmost and I will write
zero.
I will go to the leftmost and I will write zero.
OK, so this is the meaning of this thing.
OK, so this is for do not do anything.
This is five.
Do not do anything.
OK, so our second step is ready.
Now, the third step again started trading from one common when one index, OK, now for every index,
for every index I Komachi, for every index I see if Ikoma zero is zero or zero, comma G is zero,
then make then make.
I got my G equals zero.
OK, so what is the meaning of these lines.
Let us try to understand.
So we will start trading again.
OK, so now let's try it again.
So I have this element one.
OK, so for every index psychology we will check the top most and we will check the leftmost.
If any of them contain zero then right.
Zero.
OK, check the.
But most check the leftmost, so this is I'm checking the top most.
This is I am checking the leftmost.
If any of them is zero, then make a zero.
OK, so this is the top post.
This is the left.
Most voters will also make zero here.
OK, so this is obviously zero.
So do not do anything.
This is for check the leftmost so left is not digital but check the topmost sort of post zero.
So I will write the zero here.
OK, now four five.
The left just three and the top is zero.
So I will write to zero here.
OK, so after that third step, what is my error.
What is my matrix or the condition of my taxes.
One zero zero.
This is one.
OK, so this is basically zero.
This is zero.
This is three.
This is zero.
And this is zero.
OK, so this is the condition of the third step.
So what is the fourth step?
So in the fourth step, we will make use of these variables.
So I will check.
So has zero.
First row is containing a variable too.
Since it is containing a variable through what I will do, I will trade over the first row and I will
make every element zero.
OK, I will make every element zero.
So if true.
Then make every element zero.
So it will become zero and they are zero already.
OK, now basically, as know, first of all, so this is containing false.
So I will not do anything with the first column.
OK, I will not do anything with the first column.
So basically, this is my output.
Some output is basically zero zero zero zero zero zero three zero zero.
OK, so this is my output.
OK, let us verify whether our solution is correct or wrong, OK, let us verify so our input.
So this was basically one zero one one three four five zero and one.
OK, so this was our input.
Now, this element, does it also make this entire column zero, make this entire rosillo?
So this is zero.
So make this entire column zero and make this and dial zero.
So basically everything will be zero except elementary.
OK, so that means our solution is right now, what is the time and the space complexity of the solution?
So basically the space complexities or the rough one, we are just creating these two variables.
OK, and the time, complexity, what we are doing, we are simply we are trading over the matrix.
So the time complexities.
OK, so now after understanding the logic now let us write the code.
OK, so before writing the code, the efficient approach is basically it's nothing.
It is just making the use of first rule and first column.
Since we are making the use first and first column, I have to store whether the first row first column
is containing zero or not.
If they are containing zero, then our last step will be making the entire row or making the entire
column or both zero.
OK, I am repeating myself, since we are making the use of FirstRand first column, our first step
was to verify whether the first row or first column is containing Azura element or not.
And after doing this second and third step, our fourth step is basically making the first row or the
first column.
If the values are true and this is very simple, start dating from the next one, comma one.
If there is an element, if there is a zero element, we are storing the zero element with the help
of these two in the first round, first column.
Then again, start reading from the next one, comma, one for every element.
For every element.
So if the topmost element is zero, make it make the element, the leftmost element is zero, then also
make the element zero.
OK, so now let's write the code.
So writing code is very simple.
So.
Sorry, let us find out how many rules are there.
So rule number.
OK, so let's make it small.
So random, random.
OK, so this is basically matics nazis'.
And now let us so if the wrong number is basically zero, then do not have to do anything.
So if we can see that it is void and the Matrix is passed by reference, so we have to do changes in
the Matrix only, OK, we do not have to create another matrix.
So basically.
So basically, if the if there are 00, if they are not all, basically, then you can simply return.
OK, now let us also find the numbers.
How many are there?
So for doing this, but again.
Right, this is nothing but mattocks of zero nazis'.
Again, you can write if there are no columns, you get written.
Now, our first step was to contain, if you're going to see our first step was to create two variables,
OK, two boolean variables.
So has 040.
And similarly, so this is false initially.
And similarly, our second element.
Second boolean variable, so this is has zero first column.
Now, let us celebrate the values of these two.
OK, so first let us check for the first row.
OK, so.
Those first rule contains a zero.
OK, now let's check.
So therefore, we have to iterate over the columns, OK?
So if.
So if the first row and the column.
As containing the element zettl.
Then why do you have to do so, we have to update the value of this variable.
We will make it through.
And let's break the loop.
OK, now let us do the same thing for the first column.
OK, let's copy the so-called.
So this is column basically, so this first column contains a zero element.
OK, now this time we will read over the raw number.
We will add it over the rules, OK?
And this will be G and this will be basically zero, OK, and.
This will be basically has zero first column.
OK.
Now, let's move ahead, so what we have to do, we have to find truth and we have to store that information
in the first row, the first column.
OK, so now it's time to make the use of so we will make use of first rule and column.
OK, so for doing this, what will do so for doing this.
What will do.
We will find zero element and after finding the zero element we will store the raw number and the column
number and we will store data on the continent where we will store the information and first row and
column OK and first row and column.
So now let's as I did and remember, we have to start iterating from index one, OK, from index one.
So now let us say trade.
OK, we have to start from one.
Nor do we have to check whether this current element is a zero element or not.
So if metrics is basically if this element is a zero element, then we have to store the information,
OK, in the first row and first column.
So matrix of I zero is basically zero and similarly matrix of zero and G is basically zero.
OK, topmost leftmost you can see here.
OK, so if a current element is zero, what we are doing, make the top Muslimin zero, make the leftmost
element zero.
OK, we are doing this step and now we will do this step.
OK, we will start trading from one component and for every element we will check if the top element
zero make the element zero with the leftmost element.
Zero zero.
OK.
So the court will be again, we have to do the same thing.
It will start at trade from common now for every element.
OK, we have to check for every element.
Now, for every element we have to check, so what we have to check, we have to check the topmost element
and the leftmost element.
So if metrics of, let's say leftmost, so this will be basically zero, M.G..
So if this is zero.
Or.
The topmost element, so that will be zero energy, OK, zero zero and Jayate column.
If this is zero, then we have to make the element zero.
So basically take a selfie and it's is basically zero now.
Fourth step.
So what is the fourth step forward step is basically if has zero first or has the first column is containing
a brewery will then make every element in that brewer column zero.
OK.
So set the rules for first rule.
OK, so if.
Letters copied the name of the variable.
So if this very well is true, that means the first race containing Azura element initially, so we
will make the NBA Rosero.
OK, so we're making the entire Rosero.
We have to get rid of the columns.
OK, we are making the first roseto and for making the first Rosero, we have to hydrate already.
No, we have to read over the columns.
And similarly, the same situation with the first column.
So set the rules for first column.
And let's change the name of the variable, so this is a zero first column.
So has your first column.
So what we have to do for setting the first column zeros, we have to rotate over their own numbers,
we have to trade over the rules.
OK, so this will be rule number.
So whether or no.
And the number is zero.
OK, so I think we did everything fine.
Let's send our code and then we will submit.
OK, so what we did wrong.
OK, so everything seems fine.
OK, so I forgot to change the condition here, so this will be basically a.
And this will be zero.
OK, so this was wrong.
OK, so we have to check basically the leftmost and the topmost, so.
I think now this is fine.
OK, so now to some.
OK, so our coders are working fine.
OK, so let us take one more example.
So the main aim, OK.
So the main idea, the basic idea behind solving this question is basically make use of first column.
OK, we have to make the use of first rule and first column for storing the information about the zero
element in the Matrix.
OK, and since we are storing the information in the first round first column, we have to maintain
two variables.
We have to first check whether the first choice containing any Element Zero or the first column is containing
element zero.
OK, let us take one more example.
So let's say one two three four zero five to seven three four zero two one four five seven nine two
one three.
And let's take let's make zero here and let's say seven.
OK, so what we have to do is step one, take two variables has zero.
First row has zero.
First column.
Initially, they both are false.
OK, since the first row is containing a variable as irrelevant.
So this will become true.
And the first column is not containing and is irrelevant.
So it will remain false.
Now the second step starting from here, we will go right.
And we will go down OK.
This element is zero.
So make this element zero and make this element zero.
So two one four five four zero since I have zero here.
Make this element zero.
Make this element zero nine two one three seven.
Do not do anything.
Step three again, we will read.
OK, we will iterate from the next one.
Go, go.
Right.
OK, so this element is three Jacoby leftmost so this is zero.
So I will write zero here.
This is zero four two four one zero zero zero eight zero zero four zero zero zero.
So this will be zero and the topmost element is zero for nine.
So make it zero four two.
Leftmost element is seven, but most elements do not do anything for one leftmost element, the seven.
But the topmost element is it also will make zero.
Here again, this is zero.
So I will make zero here again.
This is zero.
So I will make a zero here.
OK, so after step three, what is the condition of the array?
So this is basically when I have two, I have zero zero zero.
I have a zero here.
I have zero here.
I have seven here I have zero zero zero zero zero zero zero zero zero zero two zero zero zero.
OK, so now it's time for a step for a first step for what we have to do.
We have to make the first zero because it contains truth.
So we have to make the first row zero.
So I will write zero here and I will write zero here.
And this is my answer.
This is our answer.
OK, only these two elements will ruin, everything will become zero.
OK, everything will become zero except these two elements.
OK, so I'm a beating myself.
What is the time and the space complexity?
So time is basically we are just writing our diary and space complex.
It is our draft one.
OK, so if you have any doubt in this question, you can ask me.
OK, thank you.