k
positions without using extra space.k
can be greater than the size of the array.rotateLeft({1,2,3,4,5},2) --> {3,4,5,1,2}
k
can be greater than the size of the array. Use the modulo (%) operator to find the actual number of shifts needed.
actualShifts = k % size
. % is the Modulo operator.0
to sz - actual_shifts-1
sz - actual_shifts
to sz-1
public static int[] rotateLeft(int[] arr, int k) { }
C
Java
Python