We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
your code is quite short so without reading I guess you are doign a naive approach. To speed up stuff like this you have to precompile metadata and work on it instead of every individual value. So think how you can rotate a matrix without rotating each element step by step their positions one by one.
As a second hint write a function: GetValueOfRotatedPosition(int i, int j, matrix m, int r) that will return the value of m[i][j] rotated by r in O(1) or as close as possible. Any heavy computation has to be done beforehand to build up the metadata so this function can execute quick.
Cookie support is required to access HackerRank
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 →
your code is quite short so without reading I guess you are doign a naive approach. To speed up stuff like this you have to precompile metadata and work on it instead of every individual value. So think how you can rotate a matrix without rotating each element step by step their positions one by one.
As a second hint write a function: GetValueOfRotatedPosition(int i, int j, matrix m, int r) that will return the value of m[i][j] rotated by r in O(1) or as close as possible. Any heavy computation has to be done beforehand to build up the metadata so this function can execute quick.