Explained every single doubt that you can have. Please Upvote if you like solution 🙏
Intuition\nIt is clear that if we want to minimize the cost [abs(nums[i]-x)], we need to take a number occurring in middle range. Here, we would go with median 
# Intuition\nIt is clear that if we want to minimize the cost [abs(nums[i]-x)], we need to take a number occurring in middle range. Here, we would go with median to get a central value because median is not a good representation of data in all cases, as it can be skewed.\n\nFor Example: [1,1,1,1,100]. \nHere Mean=26\nCost=25+25+25+25+75=175\n\nMedian=1\nCost=0+0+0+0+99=99                \n\n# Approach\nSort the array and take its median. Please remember we need to sort the array as to get correct median. \n\nNow, take two pointers starting at median. Use two while loops(one for exploring left side of median and one for right side), to run till you do not get palindromic number.\n\nAs we get numbers from bothsides, iterate the array and calculate cost arising from both findings. Return the min cost.\n\nPlease note we can initialise both the pointers to start from median as it is best case if median itself is palindromic!\n\n\n# Complexity\n- Time complexity:\nO(NlogN+1+1+N)=O(NlogN)\nTC occurs maily due sorting and iterating array.\nPalindrmic check is O(1) as it converts int to string and number.length<=10\nAlso while loops cost negligible as palindromic numbers are not too far from any number.\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\n    boolean isPalindromic(long x){\n        String str=Long.toString(x);\n        int p1=0,p2=str.length()-1;\n        while(p1<p2){\n            if(str.charAt(p1)!=str.charAt(p2)){\n                  return false;\n            }\n            p1++;\n            p2--;\n        }\n        return true;\n    }\n    \n    public long minimumCost(int[] nums) {\n        int i,n=nums.length;\n        long median;\n        Arrays.sort(nums);\n        \n        if(n%2!=0){\n            median=1L*nums[n/2];\n        }\n        else{\n            median=((nums[n/2]+nums[(n/2 -1)])/2)*1L;\n        }\n        \n        long cost1=0,cost2=0;\n        long p1=median,p2=median;\n    \n        while(!isPalindromic(p1)){\n            p1--;\n        }\n        \n        while(!isPalindromic(p2)){\n            p2++;\n        }\n        \n        //System.out.println(median+" "+p1+" "+p2);\n        \n        for(i=0;i<n;i++){\n            cost1+=1L*Math.abs(nums[i]-p1);\n            cost2+=1L*Math.abs(nums[i]-p2);\n        }\n        return Math.min(cost1,cost2);\n    }\n}\n```
['Sorting', 'Java']