Instead of moving one by one, divide the array into different sets where the number of sets is equal to the GCD of N and d (say X. So the elements which are X distance apart are part of a set) and rotate the elements within sets by 1 position to the left. 

  • Calculate the GCD between the length and the distance to be moved.
  • The elements are only shifted within the sets.
  • We start with temp = arr[0] and keep moving arr[I+d] to arr[I] and finally store temp at the right place.
  • Reversing the array a couple of times, will be required in this.