
Ninja continues to walk even if he steps outside the matrix in a clockwise spiral direction.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains two space-separated integers ‘N’ and ‘M’, denoting the number of rows and columns of the matrix.
The second line of each test case contains two space-separated integers, ‘R’ and ‘C’, denoting the initial coordinates of Ninja.
For each test case, return the list of coordinates present on the matrix in the order Ninja visited them.
Output for each test case will be printed in a new line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 1000
1 <= M <= 1000
0 <= R < N
0 <= C < M
Time Limit: 1sec
We can simulate the position of Ninja at each time ignoring if he is on or off the matrix. Just by a little observation, we can note that the length of the straight paths are 1, 1, 2, 2, 3, 3, 4, 4, 5, 5…. This means that we move 1 step east, 1 step south, 2 steps west, 2 steps north, 3 steps east, and so on.
We can use this observation to simply simulate the position of Ninja and append the coordinates to a RESULT list if it lies in the matrix.
Algorithm: