Simplest Solution with  Explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can see that in question, it generally ask about the minimum operation to make all e
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can see that in question, it generally ask about the minimum operation to make all elements same and another is that element should be palindromic. So we find the element from the array and then find the nearest palindromic element of it.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1- Sort the array.\n2- Find the element from the array which give the minimum cost to convert every element as same.\n3- find two nearest palindromic integer one of which is greater than element and other will be greater than that.\n4- From these two element that we get from step 3 , find the minimum cost got from them. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn) for sorting.\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    bool isPalindrome(string s){\n        int n=s.length();\n        int i=0,j=n-1;\n        while(i<j){\n            if(s[i]!=s[j]){\n\n                return false;\n            }\n            i++,j--;\n        }\n        return true;\n\n    }\n    long long minimumCost(vector<int>& nums) {\n        int s=0;\n        sort(nums.begin(),nums.end());\n        int n=nums.size();\n        vector<long long>pref(n+1,0);\n        if(n==1)return 0;\n        if(n==2)return abs(nums[0]-nums[1]);\n        for(int i=1;i<=n;i++){\n            pref[i]=pref[i-1]+nums[i-1];\n        }\n         for(int i=0;i<=n;i++){\n            cout<<pref[i]<<endl;\n        }\n         \n        long long mn=1e15;\n        long long median=0;\n        for(int i=1;i<n;i++){\n            long long m1=nums[i-1];\n            long long left1=abs(m1*(long long)(i-1)-pref[i-1]);\n            long long right1=abs(m1*(long long)(n-i)-pref[n]+pref[i]);\n            cout<<left1<<" "<<right1<<endl;\n\n            if(left1+right1<=mn){\n                mn=left1+right1;\n                median=nums[i-1];\n            }\n           \n\n           \n\n        }\n        long long a=median;\n        while(true){\n            if(isPalindrome(to_string(a))){\n                \n                break;\n            }\n            a--;\n            \n        }\n        int b=median;\n         while(true){\n            if(isPalindrome(to_string(b))){\n            \n                break;\n            }\n            b++;\n            \n        }\n\n        long long ans1=0, ans2=0,ans3=0;\n        for(int i=0;i<n;i++){\n            ans1+=abs(a-nums[i]);\n            ans2+=abs(b-nums[i]);\n        }\n\n        long long ans=min(ans1,ans2);\n\n\n\n        return ans;\n    }\n};\n```
['Math', 'Greedy', 'Sorting', 'Prefix Sum', 'C++']