[Solved] Rotation of integers stored in an array


Some notes that can be used to speed things up:

  1. Rotating by K, when K>N, is equivalent to rotating by K%N (as each rotation of N is an expensive no-op).
  2. You don’t actually need to generate the rotated array; you just need to print the values as they would appear in the rotated array.
  3. In fact, you don’t (necessarily) need to store all of the input in an array, but just the part that can’t be printed until the last value in the array is read. (This would get the input and output intermingled if both were through the console, but not if at least one were a file.)

These can be used to turn your O(N^2) solution into an O(N) one.

1

solved Rotation of integers stored in an array