Click4Ai

5.

Easy

Write a function reverse_array(arr) that reverses the elements of an array without using built-in reverse functions or slicing tricks like [::-1].

Example:

Input: arr = [1, 2, 3, 4, 5]

Output: [5, 4, 3, 2, 1]

Constraints:

  • Array length: 1 <= len(arr) <= 1000
  • Return a new array (do not modify in-place)
  • Test Cases

    Test Case 1
    Input: [1, 2, 3, 4, 5]
    Expected: [5, 4, 3, 2, 1]
    Test Case 2
    Input: [10, 20, 30]
    Expected: [30, 20, 10]
    Test Case 3
    Input: [7]
    Expected: [7]
    + 2 hidden test cases