Didn't figure out why only median works, but not the mean? || Python
Intuition\n Describe your first thoughts on how to solve this problem. \nI am still not clear why mean doesn\'t work here, I have got 4 worng ansewrs when I too
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI am still not clear why mean doesn\'t work here, I have got 4 worng ansewrs when I took the mean. Eventually, worked with median worked. Still didn\'t know why median works in this case/ \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nfind the meadian, look for a palindrom number in the both sid of the median and calculate the cost. \n\n# Complexity\n- Time complexity: O(n.log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def func(self, ar, md):\n        return sum([ abs(x-md) for x in ar])\n    def isPalindrom(self, num):\n        num = str(num)\n        return num == num[::-1]\n    def minimumCost(self, nums: List[int]) -> int:\n        mn = 10**20+7\n        nums.sort()\n        fwd = nums[len(nums)//2]\n        bac = nums[len(nums)//2]\n        f_flag , b_flag = 0 , 0\n        while True:\n            if self.isPalindrom(fwd):\n                mn = min(mn, self.func(nums, fwd))\n                f_flag += 1\n            if self.isPalindrom(bac):\n                mn = min(mn, self.func(nums, bac))\n                b_flag += 1\n            if f_flag> 0 and b_flag>0: return mn\n            fwd+=1\n            bac-=1\n```
['Two Pointers', 'Sorting', 'Python3']