You are viewing a single comment's thread. Return to all comments →
Ugly Python3 in-place solution: O(N) time, O(1) space
def rotateLeft(d, arr, lo = 0): n = len(arr) - lo d = d % n if d == 0: return arr r = n - d for i in range(r): arr[lo + i], arr[lo + d + i] = arr[lo + d + i], arr[lo + i] return rotateLeft(d - r, arr, lo + r)
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
Ugly Python3 in-place solution: O(N) time, O(1) space