🔥 NTH ELEMENT 🔥 38ms 🔥 100% 🔥
\n\nclass Solution {\npublic:\n\n    bool palindrome(string & s)\n    {\n        int l = 0, r = s.size() - 1;\n\n        while(l < r)\n        {\n            if
\n```\nclass Solution {\npublic:\n\n    bool palindrome(string & s)\n    {\n        int l = 0, r = s.size() - 1;\n\n        while(l < r)\n        {\n            if(s[l] != s[r]) return false;\n            \n            l++;\n            r--;\n        }\n        return true;\n    }\n    long long minimumCost(vector<int>& nums) \n    {\n        long long respos = 0, resneg = 0, n = nums.size();\n        auto m = nums.begin() + n / 2;\n\n        nth_element(nums.begin(), m, nums.end());\n\n        long long med = *m, pos = -1, neg = -1;\n\n        for(int i = 0; i < 4000; i++)\n        {\n            string posstr = to_string(med + i);\n            string negstr = to_string(med - i);\n        \n            if(pos == -1 && palindrome(posstr)) pos = med + i;\n            if(neg == -1 && med - i >= 0 && palindrome(negstr)) neg = med - i;\n\n            if(pos != -1 && neg != -1) break;\n        }\n        for(int i = 0; i < n; i++)\n        {\n            respos += abs(nums[i] - pos);\n            resneg += abs(nums[i] - neg);\n        }\n        return min(respos, resneg);\n    }\n};\n```
['C++']