Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Reverse In Place

Arrays & Two-Pointerseasy

Course · Section 11: Working With Arrays · Lecture 149: Simple Array Methods

Implement `reverseTwoPointer(arr)` returning a reversed array by swapping with two pointers (work on a copy).

Sample tests

Input: reverseTwoPointer([1,2,3])
Output: [3,2,1]
Input: reverseTwoPointer([])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Looping past the midpoint swaps elements back.

Learning resources

  • Wikipedia: Data structure
Approach & explanation (try first)

Swapping symmetric pairs reverses the array in O(n) time, O(1) extra space.

Loading...
⌘/Ctrl + Enter

Run your code to see results.