:: Kotlin :: Solution
\n\nclass Solution {\n    fun minimumCost(nums: IntArray): Long {\n        Arrays.sort(nums)\n        val n = nums.size\n        val median = nums[n / 2]\n     
\n```\nclass Solution {\n    fun minimumCost(nums: IntArray): Long {\n        Arrays.sort(nums)\n        val n = nums.size\n        val median = nums[n / 2]\n        var upper = median\n        var lower = median\n\n        while(upper > 0 && !isPalin(upper)) upper += 1\n        while(lower > 0 && !isPalin(lower)) lower -= 1\n\n        fun helper(n: Int) = nums.map{ Math.abs(n - it).toLong() }.sum()!!\n\n        return minOf(helper(upper), helper(lower))\n    }\n\n    fun isPalin(_n: Int): Boolean {\n        var reversed = 0\n        var n = _n\n\n        while (n > 0) {\n            val curr = n % 10\n            reversed *= 10\n            reversed += curr\n            n /= 10\n        }\n\n        return reversed == _n\n    }\n}\n```
['Kotlin']