VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-if-all-elements-of-the-array-are-palindrome-or-not/

⇱ Check if all elements of the array are palindrome or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if all elements of the array are palindrome or not

Last Updated : 30 Dec, 2024

Given an array arr[]. The task is to check if the array is PalinArray or not i.e., if all elements of array are palindrome or not. 

Examples:

Input: arr[] = [21, 131, 20] 
Output: false
Explanation: For the given array, element 20 is not a palindrome so false is the output.

Input: arr[] = [111, 121, 222, 333, 444] 
Output: true 
Explanation: For the given array, all the elements of the array are palindromes.

By Checking Each Element - O(n*k) Time and O(1) Space

The basic idea is to check each number in the array is a palindrome by converting each number to a string and comparing its characters symmetrically from both ends. If any non-palindrome is found then returns false otherwise true.


Output
true

Complexity Analysis:

  • Time Complexity:O(n*k) n is for traversing the array and k is for checking each element.
  • Auxiliary Space:O(1)
Comment
Article Tags: