You are viewing a single comment's thread. Return to all comments →
You can further reduce the time. No need to rotate the array just apply simple logic and you can do it in O(1) complexity per query.
Check this solution Circular Array Rotation
Query will be O(1) time complexity regardless of the implementation or correctness since you are accessing an indexed array. Your solution did not make accessing more efficient anymore than it is, but since you are inserting into an array in O(n) time and correctly accessing it passes all tests.