Hi guys uh Shiki welcome back to YouTube channel. So today we'll solve another question from G itself. So let's get started.
Yes. So today we have the find minimum time to reach last room. Yes.
Right. So uh on the problem statement you can see that that the problem statement uh that is on yesterday is is exactly identical of today is exactly identical that is find minimum time to reach to the last room. what we have solved yesterday with room one tact one but today's one is last room with two right so uh the problems are exactly identical only this line has extra added so what they are stating what they are stating moving between adjacent rooms take 1 second for one move and 2 seconds for the next alternating next alternating between the between the two so on yesterday they have they have clearly mentioned moving between adjacent rooms takes exactly 1 seconds but today what what the extra add-ons they have done if I can quickly go to our one node then what they are today what they are looking for they are basically stating they are basically stating something like this something like this so if so if if let's suppose you are and at these cells and and if you want to go to these cells so for every move every move no matter which moves you are you are going to taking it is going to consume you 1 second 1 second but on today's question on today's question they're basically stating for alternating moves it it's going to toggle between either 1 seconds either 1 seconds or 2 seconds either 1 seconds or 2 seconds based on the alternating move.
So on the on the very start if we are starting we are bound to start from that 0 0 uh cell if we are moving from 0 0 to this or this to any directions all the moves are going to take 1 seconds. All the moves are going to be take 1 seconds and for next alternating so for this the next alternating moves can be either this or either this. So this and this are going to take 2 seconds.
It's going to take 2 seconds. And for this for this move the possible alternating moves is either this either this either this right the top ones is bound to not going to be happens if you understand the status problem because we are going to get the minimum time to visit. So in a circular path it is not going to give us the minimum time that is the single source shortest path we are fine that algorithms that we are going to fit.
So that I think you you should I am definitely suggest you to go to the yes strategy. I'm not going to explain that part on today's video. I'm just going to give you the what extra gist you have to taking care to solve this problem.
So, so for these moves which is just alternating of the last 2 second consuming time moves. So, these are the these are the that so for this again it is going to be set 1 second. So I guess you guys are understanding first from top left when you are starting all the moves all the moves all the like down right what is the uh opportunity you have that moves are going to take 1 seconds and from there the next moves is going to take 2 seconds 2 seconds from there the next moves is going to again take 1 seconds from there it is going to take 2 seconds like this way like this way it is going to take alternating on on yesterday's problems it is always going to any move you are going to take it is going to on fixed it is going to take 1 seconds but today it is going to change alternating first 1 second then 2 seconds 1 second 2 seconds something like this.
So, so, so I am just going to the code iterations on your status code. I I have done detailed line by line explanations of your status code all together. So, I am highly highly recommend you to please go to the status videos.
After that there is a small diff we just incorporate to the status code and we will get an AC. Yes. So, in your status code we can see that we are always going to hardcodedly add 1 seconds because we know every every movement time is going to consume is going to consume 1 seconds only is going to consume 1 seconds only.
So this hard coding is not work on today's problem. This hard coding we is is not work on today's problem. So on also top of that we we need a we need a turn to kind of variables.
We need a turn to kind of variables so that we we are going we are in in good state to predict do we have to add 1 seconds or do we have to add 2 seconds. So so for every move we are basically toggle that variables. We have basically toggle that variable.
So so now you can see on that today's problem. So I I have initialized I so yesterday I have pushed three variables today I have pushed four variables. The last is the the last is the turn double variables to to basically know do I have to add one or do I have to consider two.
Do I have to consider one or do I have to consider two. So here we definitely need a change. We can't hardcodedly add one.
We we either have one or or we have either two operation two two to be considered. So here you can see like I have changed to time to move. There is a dynamic variables that is not hardly one.
And how I am predicting this either it is one or two with the turntable with the turntable. So I am initialized with time to move at zero and I am basically checking if my turn travel is going to be set. So that is the first odd or or most basically I have to say odd odd odd count of moves odd number of moves we are performing the move in in odd odd number of moves.
So if my turn to is going to be set then I am adding to plus 1 seconds else I am adding plus 2 seconds. Here you can see plus else I am adding plus 2 seconds and and also I am doing a turn to zord with one. So so how how zord is basically toggling it.
So we just basically toggle it between 1 and 0. 1 and 0. So one means we have to add 1 seconds.
0 means we have to add 2 seconds, right? So here you can see like if I can again go to my one node. So if if you just need a need like 1 0 1 0 kind of toggles for for your alternating moves.
So you can add zord. So how it is going to be add? So initially I start with one.
So so it is going to give me at time to move to be time to move is going to be at two 1 seconds. 1 seconds and next time it is z with one. Every time I am zing it once and 1 z one you you know it's zero.
So, so turn to is going to be unset and time to move on that case is going to be 26 and again it is zero. So, 0 1 again it is going to be set. So, again I am turn to move is going to be at 1 seconds like this way.
I guess you guys are getting again 1 1 is going to be unset and I am going to add turntable to be of 2 seconds. 2 seconds again 0 1 is going to be set. Then time to move is going to be 1 second like this way.
Like this way I am using using a flag which is every time if if you want to do like toggle between 1 0 1 0 1 1 0 for every move then z whatever the initial state just initialize with one or zero and do the toggling do the toggling with with z with one with z with one. So exactly that be duty I have applied here and and yeah I am correctly setting my turn to for the next loop and finally everything is same. So if if I if I can go to any div checkers if I can go to the div checkers what exactly that div I have added to today's code and yesterday's code.
So that is on yesterday room one's code. If I can go to this and if I can copy the today's code that is of room two today right. So and if I can click on point difference.
So here you can see instead of one variable instead of one three I am pushing now four because last one is turn flag that I am pushing and on current times also now we are getting three. Uh instead of three we are getting four. After unpacking the variables we are getting four.
So turn to now these extra things you can see. Now you can see that extra things because now we can't hardcode it at plus one. We have to add a dynamic variable that is time to move.
So here you can see my time to move initialized with zero and if turn to is set then I am adding plus one else I am adding plus two. Right? And every times you can see on pushing also now we have to push instead of three we have to push four four variables.
So current I am doing it with Z with ones that we just explained and like this way I am going to make every time it is toggle between 0 and one. 0 and one means I'm going to add once and zero means I'm going to add so see guys so that's extra lines I have added to that particular problems and and I got an and I got an so I'm definitely definitely repeatedly suggest you today's question we you guys are don't able to understand if you are not go to the status video so so I'm highly encourage you to go to the yesterday's video and come on today's video so that you can get the entire gist of this problem and and also before of that please go to the digra dig playlist first video at least where we have explained our templates so that you can get your feels and and mostly I am 100% sure you guys are able to solve on of these particular problems without without even seeing the videos. So that's the reason I'm making the video in the following orders and report also giving the problems in the following order so that you just make a small tweak on the yesterday's code and and you are getting AC of the today's code.
Yes. and time complexity and space complexity I'm not going to type diff that is also exactly same that we have explained yesterday and it is bound to be the most optimal time and space complexity that you can achieve for this particular video and so so that's it then for for today and if you guys are able to understand till this point so so so please please please do please do subscribe to our channels I guess you guys are already doing please do please do subscribe to our channel and please share the videos to your friends what also preparing for top product based company and rushing of theirs and please turn on the notification so that when we are going for next video you'll get the notification as soon as possible So that's it guys. That's it for today.
Let's meet tomorrow with another beautiful lesson. Bye guys. Bye-bye.