Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 787 Bytes

File metadata and controls

26 lines (20 loc) · 787 Bytes

Coding Problems

RotateMatrix

Given a 2D NxN matrix, visualize it as concentric circles. You have to find the rotated matrix where each element in the circle is rotated by 1 position layer by layer in an alternate clockwise and anticlockwise direction.

Input Format:

First line of input contains an integer, N.
Then follow N lines, each containing N space separated integers. These numbers are the entries of given matrix.

Output Format:

Print to output the resultant matrix. Each row has to be printed in a separate line and within each row adjecent numbers should be separated by a space.
Sample Input:
  4
  2 3 4 5
  1 6 7 8
  4 2 1 9
  5 3 2 4

Sample Output:
  1 2 3 4
  4 7 1 5
  5 6 2 8
  3 2 4 9