Spiral Matrix Problem Statement

You are given a N x M matrix of integers. Your task is to return the spiral path of the matrix elements.

Input

The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains two single space separated integers N and M, denoting the number of rows and columns respectively.
The next 'N' lines, each containing 'M' single space-separated integers representing the elements in a row of the matrix.

Output

For each test case/query, print the spiral path of the given matrix.
Output for every test case will be printed in a separate line.

Example:

Example Of Spiral Path:

Spiral Path

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 102
  • 1 ≤ M ≤ 102
  • -109 ≤ mat[i][j] ≤ 109
  • Time Limit: 1 second
Note:

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

Be the first one to answer
Add answer anonymously...
Salesforce Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter