Sir I was getting a TLE in one test case…
Sir can you please send me the code.
My code is:
Getting a TLE in one test case
you need to go by a more optimised approach
here i sharing the optimised approach with you…
Algorithm:
- There is N/2 squares or cycles in a matrix of side N. Process a square one at a time. Run a loop to traverse the matrix a cycle at a time, i.e loop from 0 to N/2 – 1, loop counter is i
- Consider elements in group of 4 in current square, rotate the 4 elements at a time. So the number of such groups in a cycle is N – 2*i.
- So run a loop in each cycle from x to N – x – 1, loop counter is y
- The elements in the current group is (x, y), (y, N-1-x), (N-1-x, N-1-y), (N-1-y, x), now rotate the these 4 elements, i.e (x, y) <- (y, N-1-x), (y, N-1-x)<- (N-1-x, N-1-y), (N-1-x, N-1-y)<- (N-1-y, x), (N-1-y, x)<- (x, y)
- Print the matrix.
optimised code:
u have taken 2D array size to be just 10*10
permissble 1000*1000
update the size to atleast 21
hi do u still have any doubt ??
int a[10][10];
should be a[1000][1000];