Let's left rotate the array by one position.
{
"array": [10,20,30,40,50],
"showIndices": true
}
Store the first element 10
in a temporary variable.
Shift index 1
Move 20
from index 1 to index 0.
{
"array": [20,20,30,40,50],
"showIndices": true,
"highlightIndices": [0],
"labels": { "0": "updated" }
}
Shift index 2
Move 30
from index 2 to index 1.
{
"array": [20,30,30,40,50],
"showIndices": true,
"highlightIndices": [1],
"labels": { "1": "updated" }
}
Shift index 3
Move 40
from index 3 to index 2.
{
"array": [20,30,40,40,50],
"showIndices": true,
"highlightIndices": [2],
"labels": { "2": "updated" }
}
Shift index 4
Move 50
from index 4 to index 3.
{
"array": [20,30,40,50,50],
"showIndices": true,
"highlightIndices": [3],
"labels": { "3": "updated" }
}
Place the first element at the end
Set 10
to index 4.
{
"array": [20,30,40,50,10],
"showIndices": true,
"highlightIndices": [4],
"labels": { "4": "rotated" }
}
Final Result:
Array after left rotation: [20, 30, 40, 50, 10]