Reverse Array in Place
Given an array of integers, reverse the elements of the array in place. You should modify the input array directly without using an additional array for the result.
[ 1, 2, 3, 4, 5 ]
Explanation. Reversing the array [1, 2, 3, 4, 5] results in [5, 4, 3, 2, 1].
[ 9 ]
Explanation. An array with a single element remains unchanged when reversed.
[ 10, 20 ]
Explanation. Reversing the array [10, 20] results in [20, 10].
Follow-up: How would you extend your solution to handle arrays containing different data types such as strings or floating numbers?
1. The input array must contain at least one element. 2. The elements of the array will be non-negative integers. 3. Do not use built-in reverse functions; the goal is to manually implement the reverse logic.
- Views
- 3