Palindromic Array | Practice | GeeksforGeeks

Given a Integer array A[] of n elements. Your task is to complete the function PalinArray. Which will return 1 if all the elements of the Array are palindrome otherwise it will return 0.
 
Example:
Input:
2
5
111 222 333 444 555
3
121 131 20

Output:
1
0

Explanation:
For First test case.
n=5;
A[0] = 111    //which is a palindrome number.
A[1] = 222   //which is a palindrome number.
A[2] = 333   //which is a palindrome number.
A[3] = 444  //which is a palindrome number.
A[4] = 555  //which is a palindrome number.
As all numbers are palindrome so This will return 1.


Constraints:
1 <=T<= 50
1 <=n<= 20
1 <=A[]<= 10000
0
jpragati052 days ago
CAN ANYONE TELL ME WHAT'S WRONG IN THIS CODE????
class GfG
{
    static boolean is_palindrome(int i){
        int n=i;
        int num=0;
        while(n!=0){
            int rem=n%10;
            num=num*10+rem;
            n=n/10;
        }
        if(num==i)
        return true;
    return false;
    }
	public static int palinArray(int[] a, int n)
           {
                  //add code here.
                  for(int i=0;i<n;i++)
                      if(is_palindrome(a[i]))
                      return 1;
                     return 0;
           }
}
IT IS NOT PASSING THE T.C.
0
harshscode5 days ago
int PalinArray(int a[], int n)   {       int sum=0;    for(int j=0;j<n;j++)    {        int p=a[j];        sum=0;    while(p)    {               int rev=p%10;        sum=sum*10+rev;        p=p/10;    }    if(sum==a[j])    continue;    else    return 0;                }    return 1;   }
0
alexrace182 weeks ago
 int digito,reversa=0,copia;                                  for(int i=0;i<n;i++){                     copia=a[i];                     reversa=0;                     while(a[i]!=0){                         digito=a[i]%10;                         reversa=reversa*10+digito;                         a[i]=a[i]/10;                     }                                          if(copia!=reversa){                         return 0;                     }                 }                                  return 1;
0
rsbly730095
This comment was deleted.
0
kartikkeyankant2 weeks ago
C++ easy solution using array
class Solution {
public:
   bool pal(int x){
       int arr[10000];
       int i=0;
       while(x){
           arr[i++]=x%10;
           x=x/10;
       }
       for(int j=0;j<=i/2;j++){
           if(arr[j]!=arr[i-1-j])return false;
       }
       return true;
       
   }
   int PalinArray(int a[], int n)
   {
    for(int i=0;i<n;i++){
        if(!pal(a[i]))return 0;
    }
    return 1;
   }
};

0
pratyushparida83 weeks ago
def PalinArray(arr ,n):   for i in arr:       if str(i)!=str(i)[::-1]:           return 0   else :       return 1 
0
avijit1126be203 weeks ago
//java solution
class GfG{public static int palinArray(int[] a, int n)          {                 //add code here.                boolean flag = true;                 for(int i=0;i<a.length;i++)                 {                     String str1=Integer.toString(a[i]);                     String str2 = "";                     while(a[i]!=0)                     {                         int rem = a[i]%10;                         str2 += rem;                         a[i] /= 10;                     }                     if(!str1.equals(str2))                     {                         flag = false;                         break;                     }                      }                 if(flag==false)                 {                     return 0;                 }                 return 1;          }}
+1
aloksinghbais023 weeks ago
C++ solution having time complexity as O(N*max(log(arr[i]))) and space complexity as O(max(log(arr[i]))) is as follows :- 
 
Execution Time :- 0.0 / 1.1 sec
 
string helper(int n){       string ans{};       while(n){           int ld = n % 10;           n /= 10;           ans += to_string(ld);       }       return (ans);   }      bool check(string str){       int i = 0, j = str.length()-1;       while(i < j){           if(str[i] != str[j]) return (false);           i++,j--;       }       return (true);   }      int PalinArray(int a[], int n){    for(int i = 0; i < n; i++){        string str = helper(a[i]);        if(!check(str)) return (0);    }    return (1);   }
+1
hashshamkhan200361 month ago
 int PalinArray(int a[], int n)   {    // code here    for(int i=0;i<n;i++){        int temp=a[i];        int ans=0;        while(temp>0){            int r = temp%10;            temp=temp/10;            ans=(ans*10)+r;                                }        if(ans!=a[i]){            return 0;        }    }    return 1;   }
0
pravinshelke844
This comment was deleted.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.