median finding and nearest palindrome simple solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    typedef long long ll;\n   private:\n    bool isPalindrome(int n) {\n        int t = n;\n        int num = 0;\n        while (t) {\n            num = num * 10 + t % 10;\n            t /= 10;\n        }\n        return num == n;\n    }\n\n    pair<int, int> func(int n) {\n        int p = n + 1;\n        int q = n - 1;\n        while (!isPalindrome(p)) p++;\n        while (!isPalindrome(q)) q--;\n        return {p, q};\n    }\n\npublic:\n    long long minimumCost(vector<int>& nums) {\n        int n = nums.size();\n        sort(nums.begin(), nums.end());\n        int idx = n / 2;\n        int idx2 = (n % 2 == 0) ? idx - 1 : -1;\n\n        if (n == 1) {\n            if (isPalindrome(nums[0])) return 0;\n            pair<int, int> palindromes = func(nums[0]);\n            return min(abs(nums[0] - palindromes.first), abs(nums[0] - palindromes.second));\n        }\n\n        long long ans1 = 0, ans2 = 0;\n\n        int num = nums[idx];\n        pair<int, int> palindromes = func(num);\n        if (isPalindrome(num)) {\n            for (int i = 0; i < n; i++) {\n                ans1 += (abs(nums[i] - num));\n            }\n        } else {\n            ll v1=0,v2=0;\n            for (int i = 0; i < n; i++) {\n                v1 += abs(nums[i] - palindromes.first); v2+= abs(nums[i] - palindromes.second);\n            }\n            ans1 = min(v1,v2);\n        }\n\n        if (idx2 != -1) {\n            num = nums[idx2];\n            palindromes = func(num);\n            if (isPalindrome(num)) {\n                for (int i = 0; i < n; i++) {\n                    ans2 += (abs(nums[i] - num));\n                }\n            } else {\n                ll v1=0,v2=0;\n                for (int i = 0; i < n; i++) {\n                    v1 += abs(nums[i] - palindromes.first);\n                    v2+=abs(nums[i] - palindromes.second);\n                }\n                ans2=min(v1,v2);\n            }\n        }\n\n        return (n % 2 == 0) ? min(ans1, ans2) : ans1;\n    }\n};\n```
['Sorting', 'C++']