Sort and start from middle out; avoid my mistake!!! DONT add even arr len logic
the idea is we get the median and then go middle out keeping track of left and right pointers until both of them hit palindromes\n\nDO NOT add extra logic for w
the idea is we get the median and then go middle out keeping track of left and right pointers until both of them hit palindromes\n\nDO NOT add extra logic for when len(nums)%2==0 i fcked up q3 and failed because i thought i had to do some extra cases for even length it doesnt matter\n# Code\n```\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        def isPalindrome(n):\n            n = str(n)\n            left = 0\n            right = len(n)-1\n            while left<right:\n                if n[left]!=n[right]:\n                    return False\n                left+=1\n                right-=1\n            return True\n        def getCost(p):\n            cost=0\n            for num in nums:\n                cost+=abs(num-p)\n            return cost\n        nums.sort()\n        n = len(nums)\n        mid = n//2\n        left = nums[mid]\n        right = nums[mid]\n        while not isPalindrome(left):\n            left-=1\n        while not isPalindrome(right):\n            right+=1\n        cost1 = getCost(left)\n        cost2 = getCost(right)\n        return min(cost1,cost2)\n```\n\n# bad code and how i failed:\nif nums is even then i originally had two pointers on left and right where left!=right\n\nhowever the palindrome could be in between left and right so i scanned everything from left and right this introduces more time complexity so i got TLE \n```\nclass Solution:\n    def minimumCost(self, nums: List[int]) -> int:\n        def isPalindrome(n):\n            n = str(n)\n            left = 0\n            right = len(n)-1\n            while left<right:\n                if n[left]!=n[right]:\n                    return False\n                left+=1\n                right-=1\n            return True\n        def getCost(p):\n            cost=0\n            for num in nums:\n                cost+=abs(num-p)\n            return cost\n        nums.sort()\n        n = len(nums)\n        mid = n//2\n        palindromes = set()\n        left = nums[mid]\n        right = nums[mid]\n        if n%2==0:\n            left=nums[mid-1]\n            for i in range(left,right+1):\n                if isPalindrome(i):\n                    palindromes.add(i)\n        while not isPalindrome(left):\n            left-=1\n        while not isPalindrome(right):\n            right+=1\n        palindromes.add(left)\n        palindromes.add(right)\n        ret=float(\'inf\')\n        for p in palindromes:\n            ret=min(ret,getCost(p))\n        return ret\n\n```
['Sorting', 'Python3']