Program to cyclically rotate an array by one in Python | List Slicing
Given an array, cyclically rotate the array clockwise by one. Examples:
Input: arr = [1, 2, 3, 4, 5] Output: arr = [5, 1, 2, 3, 4]
We have existing solution for this problem please refer Program to cyclically rotate an array by one link. We will solve this problem in python quickly using List Comprehension. Approach is very simple, just remove last element in list and append it in front of remaining list.
[5, 1, 2, 3, 4]
Time Complexity: O(n)
Auxiliary Space: O(1)