Hi, everyone, welcome to this new video.
So in this video, we are going to discuss about this question night on a chessboard.
So we have this night and this night can move in each direction.
So these are the total eight directions possible in which the knight can move.
Right.
So Knight can move in total eight directions from a given box, from a given cell.
Now, given this chess board, so a normal chess board is of size across it.
But in this problem, it is given that the dimension of the chess board will be given to us and they
do, the damage of the chess board will be given to us as input.
So we cannot assume it is a closet.
OK, so given this source point.
So this whole point can be any point in the chessboard, it can be this, it can be this.
It can be this.
So any point can be the source point.
And we are also given the destination point.
Right.
So we are given any source point.
Let's say this is the whole point and this is the destination point.
Right.
So so this point means your night is presented.
That is the meaning of swords point, the position, the point at which your knight is standing.
Right.
And we need to tell whether the knight can move to a destination or not, whether Knight can move to
the destination point or not, if it is able to move to the destination point, then you need to return
the minimum number of moves.
You need to return a minimum number of moves in which Knight will be able to reach the destination point
from this source point.
Right.
So one example is given to us here, and this is the example, right?
So in this example, it is given that the dimension of the chessboard are eight.
Crossett So.
McCrossin So the dimension of chessboard is it?
CROSSETT The starting point is one and one.
So one and one is this whole point.
Your night is present at this position and this is the destination point.
So you want to reach here.
This is the destination point.
This is your source point, this is his point.
This is an point.
Your night is present at this point and you need to return in minimum number of moves.
You will be able to reach their destination.
So it is saying in six moves.
In six moves.
So six is the minimum number of moves.
Remember, these are the minimum number of moves required.
So in six moves, Knight will be able to move to the destination and it will be able to reach the destination
point.
And if you are not able to reach their destination point, then in that case you need to return minus
one.
And if you are able to reach, then you need to return the minimum number of moves.
Right.
So this is the problem statement.
I hope you have understood the problem statement.
So again, what is this?
What we need to do?
We need to find out the shortest path.
What is the given input?
So given input is the grid.
That is a graph.
So given input is a graph.
Right.
We can visualize the given board as graph and virtually the nodes nodes will be this will be one node,
this will be another node.
Similarly, we will have nodes in between right where the knights can move.
So we can visualize this problem as a graph and we need to find out the shortest path and for finding
out the shortest.
But we use BFW algorithm, right?
So this problem is nothing but just the variation of BFX.
So you need to write the code for Beerfest problem for finding out minimum number of moves.
So we have already a very similar problem in our last video.
So this was the problem, shortest button by animatics.
So in this problem also for finding out the shortest path, we use the best algorithm.
So we're going to do just copy the entire code and paste the entire code here and just do the modification
according to the U.N. problem statement.
And that's it.
Right.
So you need to do a few modifications.
Right.
So what few modifications can be so the few modifications can be a member.
We created the area and divided the change in the right direction.
So obviously this will change according to the night's move.
Right.
So night night used to move in two point five moves late.
So you need to change the X and you need to change it by changing direction, changing direction.
What else do you need to change?
So here the grid is basically one indexed, based and not zero indexed based.
So you need to check you need to modify the code according to that rate.
So the end point is eight compute rate and the chessboard is a size eight crossette.
So here we can identify the indexing is one index based and not zero indexing.
So you need to do some modification according to that.
So there will be few modifications that you need to do in the previous code and that code will work
absolutely fine here.
So I highly recommend that you try modifying the existing code and if you are able to do that, then
it's very good.
So ideally, you should be able to convert this code easily into the into the current problem code.
Now, you don't just build.
Right?
So I will be writing the code and I will be doing modifications in this code in front of you in the
next room.
But I highly recommend that you must give it a try.
Right.
So this is all about this device.
In next, we will be writing the code for this problem.
I will see you in the next one.
Thank you.