VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-check-if-an-array-is-palindrome-or-not/

⇱ Array elements form a palindrome - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Array elements form a palindrome

Last Updated : 19 Apr, 2026

Given an array, the task is to determine whether an array is a palindrome or not.
Examples:

Input: arr[] = [1, 2, 3, 2, 1]
Output: true
Explanation: Elements match from both ends, 3==3, 6==6, middle 0, all match.

Input: arr[] = [1, 2, 3, 4, 5]
Output: false
Explanation: First and last elements differ, 1 != 5, so it is not a palindrome.

Two Pointer Technique - O(n) Time and O(1) Space

Traverse the array from index 0 to n/2, comparing each element arr[i] with its corresponding element from the end arr[n - i - 1]. If any pair does not match, the array is not a palindrome; otherwise, it is a palindrome.


Output
Palindrome

Using Recursion - O(n) Time and O(n) Space 

First compares the first and last elements, and if they match, then recursively check the remaining subarray by moving inward by begin + 1, end - 1. If all pairs match, the array is a palindrome.


Output
Palindrome
Comment
Article Tags:
Article Tags: