Arrays: Left Rotation

  • + 0 comments

    But isn't the whole point that you are not placing them as they come, the array is pre-populated and then rotate it. My solution is O(dn), not sure if there is anything better. Clearly I am not an algorithm guy (anymore)!

    for (int i = 0; i < d; i++) { int pop=a[0]; //shift left for (int j = 1; j < a.length; j++) { a[j-1] = a[j]; } //push a[a.length-1]=pop; }