You are viewing a single comment's thread. Return to all comments →
I solve it creating arrays for each rotation. Like for example:
6 4 7 1 2 3 4 16 17 18 5 15 24 19 6 14 23 20 7 13 22 21 8 12 11 10 9 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [17, 18, 19, 20, 21, 22, 23, 24, 0, 0, 0, 0, 0, 0, 0, 0]]
0-Calculate n. of arrays and max for each one.
1-Read into arrays, in the write order.
2-Print arrays (i+rotation)%maxArr
Where in this example maxArr is 15 for 1st and 8 2nd.
(Read and Print is almost the same code to find the positions)
or this with 3 arrays
6 7 1 1 2 3 4 5 6 7 22 23 24 25 26 27 8 21 36 37 38 39 28 9 20 35 42 41 40 29 10 19 34 33 32 31 30 11 18 17 16 15 14 13 12 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 0, 0, 0, 0, 0, 0, 0, 0], [37, 38, 39, 40, 41, 42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
and so forth.
https://www.hackerrank.com/challenges/matrix-rotation-algo/submissions/code/57157720
Seems like cookies are disabled on this browser, please enable them to open this website
Matrix Layer Rotation
You are viewing a single comment's thread. Return to all comments →
I solve it creating arrays for each rotation. Like for example:
0-Calculate n. of arrays and max for each one.
1-Read into arrays, in the write order.
2-Print arrays (i+rotation)%maxArr
Where in this example maxArr is 15 for 1st and 8 2nd.
(Read and Print is almost the same code to find the positions)
or this with 3 arrays
and so forth.
https://www.hackerrank.com/challenges/matrix-rotation-algo/submissions/code/57157720