Sorting median based nLog(n) solution
Intuition \n Describe your first thoughts on how to solve this problem. \n find the first palindromic number on both sides of the median , and the cost of opera
# Intuition \n<!-- Describe your first thoughts on how to solve this problem. -->\n find the first palindromic number on both sides of the median , and the cost of operations , return the minimum one\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(nlog(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool palindrome(int num) {\n    if (num < 0) return false; \n\n    int originalNum = num;\n    int reversedNum = 0;\n\n    while (num > 0) {\n        int digit = num % 10;\n        reversedNum = reversedNum * 10 + digit;\n        num /= 10;\n    }\n\n    return originalNum == reversedNum;\n    }\n\n    double findMedian(vector<int>& sortedArray) {\n    int n = sortedArray.size();\n    if (n % 2 == 1) {\n        \n        return sortedArray[n / 2];\n    } else {\n        \n        return sortedArray[n / 2 - 1] ;\n    }\n}\n\n    long long minimumCost(vector<int>& nums) {\n\n            sort(nums.begin(),nums.end());\n            int median=findMedian(nums); // find the median\n\n            // on both side of medians find the first palindromic number\n            int med1=median;\n            while(true){\n                if(palindrome(med1))break;\n                else med1--;\n            }\n            int med2=median;\n            while(true){\n                if(palindrome(med2))break;\n                else med2++;\n            }\n\n            // find the cost for both the possible palindromic medians and return the minimum one\n\n            long long sum1=0;long long sum2=0;\n            for(auto it:nums){\n                sum1+=abs(it-med1);\n                sum2+=abs(it-med2);\n            }\n\n\n            return min(sum1,sum2);\n    }\n};\n```
['Sorting', 'C++']