Python BasicsEasy

Reverse an Array

Detailed guide and Python implementation for the 'Reverse an Array' problem.

Problem Statement

Easy

Write a function reverse_array(arr) that takes a list of integers arr and returns a new list with the elements in reverse order. For example, [1, 2, 3] becomes [3, 2, 1].

Constraints
  • 0 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9

Examples

Example 1
Input
arr = [1, 2, 3, 4, 5]
Output
[5, 4, 3, 2, 1]
Explanation

The elements are reversed: first becomes last and last becomes first.

Example 2
Input
arr = [10, 20]
Output
[20, 10]
Explanation

Two elements swapped.

Example 3
Input
arr = [7]
Output
[7]
Explanation

Single element array reversed is the same.

Need a Hint?
Consider using Arrays-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.