Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Palindrome Array

Arrays & Two-Pointerseasy

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

Implement `isPalindromeArray(arr)` returning whether the array reads the same forwards and backwards, using two pointers.

Sample tests

Input: isPalindromeArray([1,2,1])
Output: true
Input: isPalindromeArray([1,2,3])
Output: false

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Comparing the whole reversed array is O(n) space; two pointers use O(1).

Learning resources

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

Two pointers from both ends compare mirrored elements in O(n) time and O(1) space.

Loading...
⌘/Ctrl + Enter

Run your code to see results.