Close
Topic list
Rotate Clockwise
EASY
15 mins
Matrices (2D Arrays)
Topics (Covered in this problem)
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Rotate Clockwise

Contributed by
Easy
0/40
Avg time to solve 15 mins
Success Rate 90 %
Share

## Problem Statement

#### You are given a square matrix of dimensions ‘N * N’. You have to rotate the matrix 90 degrees in a clockwise direction.

##### EXAMPLE:
``````Input: 'N' = 2, 'NUMS' = [[1, 2], [3, 4]]

Output: [[3, 1], [4, 2]]

Here the given matrix is rotated 90 degrees in a clockwise direction.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
2
1 2
3 4
3
1 2 3
4 5 6
7 8 9
``````
##### Sample Output 1 :
``````3 1
4 2
7 4 1
8 5 2
9 6 3
``````
##### Explanation Of Sample Input 1 :
``````For the first test case,
'N' = 2, 'NUMS' = [ [1, 2], [3, 4]]
After rotation 90 degrees in a clockwise direction the matrix will be:
‘NUMS’ = [ [3, 1], [4, 2] ].

For the second test case,
'N' = 3, 'NUMS' = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
After rotation 90 degrees in a clockwise direction the matrix will be:
‘NUMS’ = [ [7, 4, 1], [8, 5, 2], [9, 6, 3] ].
``````
##### Sample Input 2 :
``````2
3
5 10 4
10 6 2
10 3 3
3
3 8 2
10 3 9
6 3 2
``````
##### Sample Output 2 :
``````10 10 5
3 6 10
3 2 4
6 10 3
3 3 8
2 9 2
``````
Auto
Console