Login

All Problems

Problem title

Difficulty

Avg time to solve

Ninja and Locker

Moderate

25 mins

Split A Circular Linked List

Easy

15 mins

Convert Sentence

Easy

15 mins

Detect The Cycle

Easy

--

Minimum Knight Moves

Hard

--

Help Bob Out!

Easy

--

Best Line

Easy

20 mins

All prime numbers

Moderate

--

Zero Consecutive Sum Nodes

Moderate

20 mins

Special Sum

Easy

15 mins

Problem

Submissions

3

Problem Statement

```
As depicted in the photo below, the knight currently at (0, 0) can move to any of the 8 positions: (1, 2), (2, 1), (2, -1), (1, -2), (-1, -2), (-2, -1), (-2, 1), (-1, 2).
```

```
If X = 1 and Y = -1, then we need to find out the minimum number of steps to move the knight from (0, 0) to (1, -1).
We need at least 2 steps to move the knight to the desired position.
First move: (0, 0) -> (2, 1)
Second move: (2,1) -> (1, -1)
Here we can see that there are many ways, but we need at least 2 steps. Therefore we will return the value 2.
```

```
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows:
The first and only line of each test case contains two integers ‘X’ and ‘Y’, denoting the x-coordinate and y-coordinate of the final position of the knight.
```

```
For each test case, print the minimum number of steps needed.
Output for each test case will be printed in a separate line.
```

```
You are not required to print anything; it has already been taken care of. Just implement the function.
```

```
1 <= T <= 10
-100 <= X, Y <= 100
Time limit: 1 sec
```

```
2
1 1
1 0
```

```
2
3
```

```
For test case 1 :
(0, 0) to (2, -1) to (1,1), therefore 2 steps are required. The other possible way is (0, 0) to (-1, 2) to (1, 1), but we require at least 2 steps to move from (0,0) to (1,-1).
Hence return value 2. Refer the image for better understanding:
```

```
For test case 2 :
(0, 0) to (2, 1) to (0, 2) to (1, 0), therefore 3 steps are required. Refer the image for better understanding:
```

```
2
12 5
5 12
```

```
7
7
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code