Skip to main content
Intermediate~6 min · +40 XP

Two-Pointer In-Place Reverse

Practices: Two-Pointer Technique

Problem

You reverse the array [4, 9, 2, 7, 5] in place with converging pointers: swap arr[left] and arr[right], move both inward, stop when they meet.

What does the array look like after the algorithm finishes? (Format: comma-separated, like 3,2,1)

Examples

  • in: [1, 2, 3]

    out: 3,2,1

    Swap ends (1↔3), pointers meet at 2, done.

Constraints & conventions

  • 5 elements ⇒ ⌊5/2⌋ = 2 swaps happen.

Your answer

Solve the challenge to unlock the full approach and complexity analysis.