Arrays: Left Rotation

  • + 0 comments

    Hey, guys
    Here is a solution based on modular arithmetic for the case when k > n:

    new_index = (n + i - abs(k-n)) % n
    

    (note: n - abs(k-n) can be collapsed to a single number)