Question: In Java, rotate a square matrix counter-clockwise or clockwise 90 degreesan arbitrary number of times. You will be given a matrix ofintegers (otherwise known as
In Java,
rotate a square matrix counter-clockwise or clockwise 90 degreesan arbitrary number of times. You will be given a matrix ofintegers (otherwise known as a 2-dimensional array), that has equalheight and width. The dimension can range from 2x2 - 10x10. Youwill also be given an integer that may range from -100 to 100, thisinteger will indicate which direction to rotate the matrix and howmany times to rotate it. You are expected to return the rotatedmatrix.
direction - The number of rotations in a particular direction.If > 0 rotate the specified amount of times clockwise. else if< 0 rotate the specified amount of times counterclockwise.Otherwise, no rotations are expected.
matrix - A two-dimensional array of integers that is to berotated.
returns - The rotated matrix it was initially given.
int[][] rotateMatix(int direction, int[][] matrix)
Step by Step Solution
3.40 Rating (166 Votes )
There are 3 Steps involved in it
Answer class GFG size of matrix static final int M3 static final int N3 void fillSpiralint matMAX int m int n int temp int i k 0 l 0 k starting row in... View full answer
Get step-by-step solutions from verified subject matter experts
