VOOZH about

URL: https://www.geeksforgeeks.org/dsa/print-matrix-spiral-form-starting-point/

⇱ Print a matrix in a spiral form starting from a point - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Print a matrix in a spiral form starting from a point

Last Updated : 15 Jul, 2022

Given a matrix of size n*m, and a point P(c, r). Print the matrix in a spiral form(clockwise) starting from the point P.

Examples : 

Input : mat[][] = {{1 2 3},
 {4 5 6},
 {7 8 9}}
 Point P = (0, 2)
Output : 3 6 5 2 9 8 7 4 1
The starting point is top left which
is 3.

This problem is mainly an extension of print a matrix in spiral form.

Implementation:


Output
3 6 5 2 9 8 7 4 1 

Time Complexity: O(max(low_row,low_column) x max(high_row , high_column)) 
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: