FastPrepFastPrep
Problem Brief

Jumping Kady (Intuit India)

INTERNOA

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:

  1. Kady cannot go out of plane. If he do so then he will fall off the plane and dies.
  2. If Kady wants to take jump from point A to B then jump is only feasible if Euclidean distance between these two points is X.

Function Description

Complete the function minimumJumps in the editor.

minimumJumps has the following parameters:

  1. int m: the number of rows in the plane
  2. int n: the number of columns in the plane
  3. int X: Kady's favourite number, the jump distance
  4. int p: the row number of Kady's starting position
  5. int q: the column number of Kady's starting position
  6. int u: the row number of Kady's destination
  7. int 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

Input
m = 6, n = 5, X = 5, p = 1, q = 2, u = 6, v = 2
Output
2
Explanation

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 ≤ 1000
  • 1 ≤ X ≤ 1000
  • 1 ≤ p, u ≤ m
  • 1 ≤ q, v ≤ n
public int minimumJumps(int m, int n, int X, int p, int q, int u, int v) {
    // write your code here
}
Input

m

6

n

5

X

5

p

1

q

2

u

6

v

2

Output

2

Sign in to submit your solution.