![]() |
VOOZH | about |
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, middle0,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.
Table of Content
Traverse the array from index
0ton/2, comparing each elementarr[i]with its corresponding element from the endarr[n - i - 1]. If any pair does not match, the array is not a palindrome; otherwise, it is a palindrome.
Palindrome
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.
Palindrome