📚 PracticeEasyAlgorithm ProblemCoding Ready
Reverse an Array
Algorithm: 10-15 minutes
two-pointersarrayeasyfundamentalinterview
Updated Dec 29, 2025
Question
Problem
Given an array of elements, reverse the array in-place.
This means you should modify the original array without using extra space for another array.
Implement multiple approaches:
- Two-pointer swap (optimal in-place)
- Using built-in reverse
- Stack-based approach
After reversing:
- First element becomes last
- Second element becomes second-to-last
- And so on...
Constraints
- 0 ≤ array length ≤ 10^5
- Array elements can be any type (integers, strings, etc.)
- Must modify array in-place with O(1) extra space
Examples
Example 1
Input:
arr = [1, 2, 3, 4, 5]
Output:
[5, 4, 3, 2, 1]
Explanation: Each element swaps with its mirror position
Example 2
Input:
arr = ["a", "b", "c", "d"]
Output:
["d", "c", "b", "a"]
Explanation: Works with any element type
Example 3
Input:
arr = [1]
Output:
[1]
Explanation: Single element array remains unchanged
Example 4
Input:
arr = []
Output:
[]
Explanation: Empty array remains empty
Function Signature
def reverse_array(arr: list) -> None:
"""
Reverse the array in-place.
Args:
arr: The array to reverse (modified in-place)
Returns:
None (array is modified in-place)
"""
pass
Estimated Time
10-15 minutes
Tags
two-pointers array easy fundamental interview
Your Solution
python
Auto-saves every 30s
Try solving the problem first before viewing the solution
Learning Resources
0:00time spent