Hi, everyone.
So today we will solve this question, zigzag pattern.
OK, so the input will basically be a string and the second input will basically be the number of rules.
OK, so these are the number of rules.
Now, what we have to do since the number of rules is basically two.
So I will make two rules.
So this is rule one and this is rule two.
Now I read all the string.
OK, so so right in the first rule, then IFB.
So right.
Be in the second row then AFSC.
So right in the first row then I have this already.
OK, and this is my first rule and this is my second rule.
OK, and then first.
Right.
First rule.
So this is easy then.
Right.
Second rule.
So this is beardie.
This is really OK.
So this is the output.
OK, this is the output for Decentered AC Beardie.
OK, now let us consider this string, OK?
And the number of rows is basically three.
So this is my first row.
This is my second row and this is my third row.
OK, so now let's get rid of the string and fill this room.
OK, so this string is basically people.
Is hiding, OK, people is hiding, so I have be so right be then I have a then I have my again B then
A then and so people then I.
S is hiding, so H.
I.
All right.
I.
And Angie, OK, and now forward producing the output, so for writing the output, right, the first
row.
So first is.
B.
And so this is first row, be a edge and then right the second row.
So this is Apple s i g so a b l s i i g then right.
The third row, which is why I was so why I said OK, why I.
So this is the output for this input.
OK, so I hope you understood this question, let us see one more example.
So this question is basically a literal.
OK, so people is hiding and the number of laws is basically.
OK, so we will create four rules.
So I have this is the first rule.
This is second rule, third and fourth rule.
Now people deciding so be a Y be.
A l.
S.
Ich.
I are.
I.
And.
And OK, so we will write the output of the first row, which is span the output of Secondo, which
is a L.
S IGY, then the third row, which is why Echard then the output of falderal, which is by OK.
So this is the output for this input.
OK, you can be any less a G by H are being OK.
So our output is basically correct.
OK, so this is the question now how we can solve this question.
So this question is again a simply implementation problem.
OK, so this question is basically assembly implementation problem.
Now let's see how we can solve this problem.
OK.
So let us consider this example, people deciding and the number of rose is basically three.
So a number of sources, basically three, so a number of rows is basically three.
So what we will do, we will create.
So we will create an 80.
OK, so we will get an array of size three.
OK, so this is basically the zero index.
This is the first index of the area and this is the second index of the area.
And inside the each index, I will store a string.
So there's a index will store restring the first indexable Storrar string and the second indexable store
restring.
OK, so basically I will write something like this.
I want to create an area of a string, so let's call it string then.
Let's say the name is Star and the size will be Namaroff Rose.
OK, so if you want to create the entire area, what you write, you write and edit and size three,
but if you want to create an array of a string, so this is the syntax string.
First of all, you write the letter type so that your diapers and other types of string, then the name
of the array and then the size of the OK, so first of all, I will create this area so each index will
store a string, OK, and then we will fill the values in these indexes.
And after we have this value in these indexes, I will trade over data and what I will do.
So let's call it answer.
So I will write answered plus equals two.
So the first string, the name of the ad is basically a.
So I will write StarOffice.
OK, so this plus operator can do so with the help of this plus operator you can append boosting for
example string A's ABC and you have an industry let's call it.
D.F., OK, and I would tell physically, actually, plus the survival rate plus operators of this plus
operator can append to strings.
So this answer will contain ABC BBF.
OK, so initially our answer will be empty and then we have filled this completely.
What we will do, we will iterate over this area and then we will surplused close to a string of I guess
that is basically the name of the area.
Now let's see how we can fill this area.
OK, let us consider an example.
OK, so I have the string people is hiding.
So in this example, the number of rose is basically three, OK, since a number of Rose is basically
three, but I have to do I will create 80, I will create an area of Sastry.
And inside this area, what I will do, I will store a string.
OK, so this will store a string, this will store a string and this will store a string.
So this is zero, this is one, and this is the next.
So now let us I tripped over the string, so be right, be here then.
I have a so right here then I have I see.
Right right here then IFB.
So I cannot.
Right.
Be here because I have reached the end of the string.
So I will move up but I will move about so I will.
Right.
Be here.
OK then I have it so I will right here then I have l so I cannot right l here because this index does
not exist so I have to move down so far moving down.
I will write l here.
OK, so I have s I can write I here I have s again.
We cannot write s here.
OK, so we will write s here then.
I have it so right h here then I.
So again we cannot write I here so I will write, I hear then I ring so I and nd and G.
OK, so what is the situation.
So basically the zero index is containing this string BGH and.
The second the first index is containing this string.
And our third index is basically containing the string.
Now, what we have to do, so we have to hydrate.
Over this area, and suppose our answer is basically empty, then what we have to do, we have to right
answer because I'm in surplus now, the surplus operator can append two strings.
So let's say the name of this Ediz star.
So what I will write, I will write.
Start off I OK, so I am bending the strings.
So this is the first string which will be appended.
So this is B itchin.
Now this string will be appended so it will become a b l.
S igy and then I will bend the strings.
So this is why I r and this will be our output.
So this is basically the answer string.
OK, so very simple.
This is just the implementation problem, ok.
Only implementation problem.
Now let us write the code for this.
OK.
So now let us write the code, so input is basically a string and we have to return a string.
OK, and this is the number of rules.
So first, let us handle some very simple cases.
So if the number of rules is less than or equal to one, if there is only one rule, OK, you can do
it later than the given string because you do not have to do any changes.
OK, so now let us find out the length of the string, so this is as nazis'.
OK, so now let us create this, Eddie.
OK, so I have to create this Eddie.
OK, so you want each and short stories string.
So the syntax will be that first string, then the name of that, let's say the name of that is basically
OK.
And then the size of the area, which is basically the number of rules, OK, if the number of rules
is basically three, then the size of the area is basically three.
So this is the way to create a static area.
But we know whenever we want to create an area and whose size is basically a variable, the better way
to create that is with the help of a dynamic allocation.
OK, so instead of creating a third degree, I will create a dynamic.
So syntax will be string, then start, then the name of that which is new, and then that ended up
which is string and then the size.
OK, so while we have to create this dynamic area, why not category?
Because this value is variable.
OK.
So whenever you have a variable size, the better way is to use dynamic allocation.
OK, so string start the name of the array, so a new operator and then the other type and then they
say OK.
So strings start led the Nimoy's.
So this is new type string and size, basically endless number of arrows.
OK, so now let us trade all the string.
So I'm taking a variable role, which is initially zero, and let us take a variable step.
Also.
So now let us say straightforwardly interesting.
OK.
So for our I am using a while loop a follow up.
OK.
So now what we have to do, so the name of that is so a adverting next, I have to push so for using
the index, I have created this variable.
OK, and what role I have to push the current character.
So that's why I have created this variable.
All you can see, this is index zero.
This is index one.
This is index too.
So basically for moving these indexes, for storing these indexes, I am taking a variable role.
OK, so initially I have to put at index zero.
So that's why ruys initialized with zero then what I will do.
So I will do Roebling's plus four going to index one, then I will go to index two.
So I will again do rule plus.
Plus after reaching the index do I have to move above.
I have to move above, so basically I have to do room minus minus.
OK, so basically this plus plus and this minus minus thing.
So it'll become to make this thing is what I'm doing.
I'm keeping a variable step.
So this step is basically one.
So if I will.
Right, Roy equals rule plus step.
So this is nothing.
It is simply rule plus plus, OK, and if the value of a step is minus one, then what is the scenario?
And I am writing requested or please step, then this line will become a rule minus minus if the value
of a step is minus one.
OK, simple.
So to do this rule plus plus 10 and then again moving upward.
So we have to do two plus plus and we have to do two minus minus for doing this plus plus this minus
minus thing.
I am keeping, I'm maintaining a variable step which is initially one because we have to move down initially,
OK, and then we will reach here when we will reach at the last index I will update the value of a step
to become minus one.
Then when I will do roll cultural step this will become room minus minus.
OK, simple.
So I have to push at the next rule, OK, so this is basically a string and for pushing the element
inside the string, we have a function push back.
Push back and you can give the character so characters basically Astolfi.
OK, so now what we have to do, so either I have to move down through placeless or I have to move up
room minus minus.
OK, so how to decide?
Let's see.
So basically, I will simply ride equals rule plus step.
And now let us check.
Either we have to move.
Either we have to appreciate the value of step or not.
So if basically I am standing at zero zero, then obviously I have to move down.
So if I have to move down, so I will step backwards one so that it will become a hopeless place.
So this is where the value of step is when this will become rouble's plus.
OK, and.
If I'm at the last index, OK, so elusive.
I am at the last index of the array, so basically ROI equals equals.
And those minus one.
The last minutes of the day, you can see that it is of size and those so the last index is basically
and minus one, if I am standing at the Lastra next, then I have to move up.
OK, so for moving up, the value of step should be minus one.
OK, so this is to move up roominess minus.
We have to move up.
And this is simply Roy Chloroplast.
OK, so when we will reach the end of the for loop, our ETA is basically ready.
So this Eddie.
OK, so this area is basically ready then.
What I have to do, I have to create a string and I just have to rotate over this area and I have to
append.
These strings, OK, now let's create.
A variable answer which is initially empty.
OK, now we have to hydrate.
Over this area.
OK, this area is basically ready in order to saturate all this area.
And what we have to do, so on so goes on surplus, so this surplus operator can append two strings.
OK, so answer a question surplus.
The name of that is a and the indexers I.
OK, and when we will reach when we come out of the loop, we can return our answer.
OK.
OK, so Alcalde is working now legitimate.
OK, so our goal is working fine, nobody can do so instead of creating this, and I don't think we
can, like, update this thing also.
OK, so do not create the new string.
Let us update the previous one only.
OK, so.
This is so SMPTE empty, so I have a bit of this ring and then I'm updating the string.
So Ezequiel's.
Explicit, and then I am returning as OK, so I'm not getting news.
I, I'm just updating the Gülen string.
OK, so now let us discuss the time and the space complexity for our solution.
OK, so one thing first.
So what I'm doing here is so this is the input string, so I'm updating the input.
I'm not getting any of the string, OK.
So Ezequiel's and pretty.
OK, you can also write I have a function clearance, so it's not clear.
So this clear function and this empathy thing, they both seem.
OK, so the space complexity.
Basically, what we are doing, so we are creating a new area.
OK, so we are creating this area.
So the space complexities basically endless.
Often less than the number of rules, OK, and the time complexities, basically, we are just trading
over the string.
OK, so here we are just trading over this string of the given string.
So this is our Draffin Plus.
And then we are trading over this new area.
OK, we are trading over this new area.
So the time, complexities and rules, because the sizes and complexity is basically order of N and
order of andrews'.
OK, so this thing will be very small.
This will be like eight, three, four, five or six.
But this will be very, very large.
For example, this can be handled.
This can be like a thousand characters.
This can be 10000 Denki and so on.
So basically PN is greater than goaltend and is much, much bigger than the number of rows you can see
the time complexity is nothing.
It is just big off and on.
OK, so this is the time, complexity and also the number of rules.
This will be basically like either one or two or three.
So this really will be very, very small.
Four, five, six.
Generally this will be very, very small.
So you can also say, like my space where complexity is nothing, it is just order one.
OK, you can see because these values will be very, very small.
OK, so you can see the space complex.
It is a rough one, and if you are not comfortable with this, then you can see the space complexities,
big number of rules and the time complexities big often.
OK, so this was simply an implementation problem.
OK, so if you have any doubt in this question, you can ask me.
OK, thank you.