Minimum cost path – In 2D matrix
Kady is standing on a two-dimensional plane of size m*n square units. The plane is partitioned into unit squares. So, in total, there are m*n squares. Kady has his favorite number “X” so each time when he will jump he will take jump of “X” units.
In short, the plane can be considered a 2D matrix. Kady is currently standing at position S(p,q) where p is the pth row of the matrix and q is qth column of the matrix. Kady wants to go from his position S to his new position R(u,v) by taking jumps of exactly X units each time.
Determine if Kady can reach his destination or not. If he can reach, print the minimum number of jumps he needs to take to go from S to R.