Rotate Left by 1
Rotate array left by one position.
IntermediatePhase 4 - Level 3: TransformationExample 7 of 10
rotate-left-by-1.py
1# Take array2n = int(input("Enter array size: "))3arr = []4for i in range(n):5 arr.append(int(input(f"Element {i+1}: ")))67# Rotate left8if len(arr) > 0:9 first = arr[0]10 for i in range(len(arr) - 1):11 arr[i] = arr[i + 1]12 arr[-1] = first1314print(f"After left rotation: {arr}")
Output
Enter array size: 5 Element 1: 1 Element 2: 2 Element 3: 3 Element 4: 4 Element 5: 5 After left rotation: [2, 3, 4, 5, 1]
What's going on
Shift all elements left, move first to end.
Key Concepts:
Save first element
Shift all elements left
Place first at end
🔗Related Content
- 📖
Phase 4 - Learn Concepts
Review Phase 4 concepts and explanations
- 📝
Phase 4 - Quiz
Test your Phase 4 understanding with quiz questions
- 💻
Phase 4 - All Practice Problems
Explore all practice problems for Phase 4
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum