What is the fastest algorithm for circle shifting array for M positions? For example, [3 4 5 2 3 1 4] shift M = 2 positions should be [1 4 3 4 5 2 3
[3 4 5 2 3 1 4]
[1 4 3 4 5 2 3
Ruby example:
def move_cyclic2 array, move_cnt move_cnt = array.length - move_cnt % array.length if !(move_cnt == 0 || move_cnt == array.length) array.replace( array[move_cnt..-1] + array[0...move_cnt] ) end end