![]() |
VOOZH | about |
Given an array of integers and a number d, the task is to rotate the array to the left by 'd' positions. In left rotation, each element moves one position to the left, and the first element moves to the end of the array.
Example:
Input: [1, 2, 3, 4, 5]
d=2Output: [3, 4, 5, 1, 2]
This method rotates an array by splitting it into two parts using slicing and then joining them in reverse order.
[3, 4, 5, 6, 1, 2]
Explanation:
This method rotates an array by reversing the entire array and then reversing its parts separately.
[3, 4, 5, 6, 7, 8, 1, 2]
Explanation:
This method rotates an array by storing the first 'd' elements in a temporary array, shifting the remaining elements left, and then appending the stored elements at the end.
[3, 4, 5, 6, 7, 1, 2]
Explanation:
[3, 4, 5, 6, 7, 1, 2]
Explanation: