Finally did it | C++ solution | 5 Cases
Complexity\n- Time complexity: 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#
# Complexity\n- Time complexity: $$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    long long minimumCost(vector<int>& nums) {\n        long long int ans=LLONG_MAX,median=0;\n        int n = nums.size();\n        sort(nums.begin(),nums.end());\n        if(n%2!=0) median = nums[n/2];\n        else median = (nums[n/2]+nums[(n/2)-1])/2;\n        string t=to_string(median);\n        vector<string> pal;\n        //case-1\n        pal.push_back(to_string(pow(10,t.size()-1) -1));\n        //case-2\n        pal.push_back(to_string(pow(10,t.size()) +1));\n        // case -3,4,5\n        string prefix = t.substr(0,(t.size()+1)/2);\n        cout<<prefix<<endl;\n        long long int intg=stoll(prefix);\n        vector<long long int> v = {intg-1,intg,intg+1};\n        for(int i=0;i<3;i++){\n            string k = to_string(v[i]);\n            string postfix=k;\n            cout<<k<<endl;\n            if(t.size()%2) postfix.pop_back();\n            reverse(postfix.begin(),postfix.end());\n            string res = k + postfix;\n            pal.push_back(res);\n        }\n\n        for(int i=0;i<5;i++){\n            long long sum=0;\n            long long a = stoll(pal[i]);\n            cout<<a<<" ";\n            for(auto ele:nums){\n                sum+=abs(ele-a);\n            }\n            ans=min(ans,sum);\n        }\n        return ans;\n    }\n};\n```
['C++']