Implement Cache and Rotate Matrix | Amazon Coding Question