Hackerrank: [Algo] Matrix Rotation
- Hackerrank problem link: [Algo] Matrix Rotation problem
- My rotation approach: Github gist
- My final approach: Github girst
First I wrote rotate function that rotates one digit in anti-clockwise direction for the entire function. Then, call that function numRotation
times. However, this was very expensive. So I decided to get all digits in the circle, counts how many elements in that circle, and calculates how many times the number has to be shifted.
With this approach, everything runs under time constraints.
My rotate function:
My entire code is in the main function, so please refer to my Github girst located at the top for my final code. The reason why I did this in the main function is I was not sure how I should update my map
variable in the function.
Anyway, this problem was easy to figure out, but hard to implement. Good problem hackerrank!!