Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Rotate a 2D matrix 90 degrees clockwise.

Medium

Problem Statement

Rotate a 2D matrix 90 degrees clockwise.

Sample Input

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Sample Output

[7, 4, 1]
[8, 5, 2]
[9, 6, 3]

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
import java.util.*; public class Main { public static int[][] rotateMatrix() { int[][] matrix = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; // Your code here return matrix; } }
Log in or sign up to run or submit your code.Log inSign up
Input
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected Output
[7, 4, 1]
[8, 5, 2]
[9, 6, 3]