Jumping Kady (Intuit India)
Kady is very energetic guy and he is fond of jumping. He is standing on a two dimension plane of size m*n square units. Plane is partitioned into unit squares. So in total there are m*n squares. Kady has his favourite number 'X', so each time when he will jump he will take jump of 'X' units.
In short, plane can be considered as a 2D matrix. Kady is currently standing at position S(p,q) where p is p^th row of matrix and q is q^th column of matrix. Kady wants to go from his position S to 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 need to take to go from S to R.
Note:
- Kady cannot go out of plane. If he do so then he will fall off the plane and dies.
- If Kady wants to take jump from point
AtoBthen jump is only feasible if Euclidean distance between these two points isX.
Complete the function minimumJumps in the editor.
minimumJumps has the following parameters:
int m: the number of rows in the planeint n: the number of columns in the planeint X: Kady's favourite number, the jump distanceint p: the row number of Kady's starting positionint q: the column number of Kady's starting positionint u: the row number of Kady's destinationint v: the column number of Kady's destination
Returns
int: the minimum number of jumps required to reach the destination or -1 if it's not possible
1Example 1
In starting Kady is standing at position (1,2). From here he can jump to point (6,2) by taking 5 units of jump. From (6,2) he can go to (2,5) which is also at a distance of 5 units from his position.
Therefore, the minimum number of jumps required is 2.
Constraints
Limits and guarantees your solution can rely on.
1 ≤ m, n ≤ 10001 ≤ X ≤ 10001 ≤ p, u ≤ m1 ≤ q, v ≤ n