AlgoInsight

DSA problem

Reverse an Array In-Place

EasyArraysPattern: Two PointersbeginnerFree

Given an array of N integers, reverse it in-place without using extra space.

The two-pointer technique at its simplest. Place one pointer at the start and another at the end. Swap the elements they point to, then move both pointers inward. Continue until they meet or cross.

This runs in O(N) time with O(1) space - no extra array needed. The two-pointer pattern is one of the most versatile techniques in DSA: it powers problems like two-sum on sorted arrays, container with most water, trapping rain water, partitioning, and palindrome checks.

Examples

Example 1
Input: nums = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Explanation: The elements are reversed by swapping symmetric pairs from the outside in.

Constraints

3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.

array

Browse all DSA problems