C++ Solution | Closest palindrome lesser and greater than median
Intuition\nFind closest palindrome on left and right of median\n\n# Approach\nJust simple for loop will work\n\n# Complexity\n- Time complexity: O(N)\n\n- Space
# Intuition\nFind closest palindrome on left and right of median\n\n# Approach\nJust simple for loop will work\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    long long minimumCost(vector<int>& nums) {\n        int n = nums.size();\n        sort(nums.begin(), nums.end());\n        int med = nums[n / 2];\n        \n        long long lt, rt;\n        for(long long i = med; i >= 1; i--) {\n            string s = to_string(i);\n            string t = s;\n            reverse(t.begin(), t.end());\n            if(s == t) {\n                lt = i;\n                break;\n            }\n        }\n        for(long long i = med; i <= 1e9; i++) {\n            string s = to_string(i);\n            string t = s;\n            reverse(t.begin(), t.end());\n            if(s == t) {\n                rt = i;\n                break;\n            }\n        }\n        \n        long long ls = 0, rs = 0;\n        for(auto it : nums) {\n            ls += abs(it - lt);\n            rs += abs(it - rt);\n        }\n        \n        return min(ls, rs);\n    }\n};\n```
['C++']