Kotlin | O(1) solution
Intuition\n Describe your first thoughts on how to solve this problem. \nWe know that any targetSeconds value can be represented in a regular way, when seconds 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe know that any `targetSeconds` value can be represented in a regular way, when seconds part has range from `0` to `59`:\n* `targetSeconds` = 159\n* `minutes` = 2; `seconds` = 39.\n\nBut in our case seconds have range from `0` to `99`, that creates another possibility (in some cases) to represent given `targetSeconds` value in extended format:\n* `targetSeconds` = 159\n* `minutes` = 1; `seconds` = 99.\n\nAfter that we just need to calculate which format in \'cheaper\' to calculate given `startAt`, `moveCost` and `pushCost` parameters.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Transform `targetSeconds` to a regular and extended (if possible) formats;\n2. Calculate costs;\n3. Return cheaper.\n\n# Complexity\n- Time complexity: $$O(1)$$\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```kotlin []\nclass Solution {\n    fun minCostSetTime(startAt: Int, moveCost: Int, pushCost: Int, targetSeconds: Int): Int {\n        val variants = mutableListOf<String>()\n\n        val timeInRegularFormat = targetSeconds.asRegularFormat()\n        val costForTimeInRegularFormat = calculateCost(timeInRegularFormat, startAt, moveCost, pushCost)\n        val costForTimeInExtendedFormat = targetSeconds.asExtendedFormat()?.let { time -> calculateCost(time, startAt, moveCost, pushCost) } ?: Int.MAX_VALUE\n\n        return minOf(costForTimeInRegularFormat, costForTimeInExtendedFormat)\n    }\n\n    private fun Int.asRegularFormat(): String {\n        val minutes = (this / 60).coerceAtMost(99)\n        val seconds = this - minutes * 60\n\n        val sb = StringBuilder()\n        if (minutes > 0) {\n            sb.append("$minutes")\n        }\n        if (seconds == 0) {\n            sb.append("00")\n        } else if (seconds < 10 && sb.isNotEmpty()) {\n            sb.append("0")\n            sb.append("$seconds")\n        } else {\n            sb.append("$seconds")\n        }\n        return sb.toString()\n    }\n\n    private fun Int.asExtendedFormat(): String? {\n        val minutes = (this / 60).coerceAtMost(99) - 1\n        if (minutes >= 0) {\n            val seconds = this - minutes * 60\n            if (seconds <= 99) {\n                val sb = StringBuilder()\n                if (minutes > 0) {\n                    sb.append("$minutes")\n                }\n                if (seconds == 0) {\n                    sb.append("00")\n                } else if (seconds < 10 && sb.isNotEmpty()) {\n                    sb.append("0")\n                    sb.append("$seconds")\n                } else {\n                    sb.append("$seconds")\n                }\n                return sb.toString()\n            }\n        }\n        return null\n    }\n\n    private fun calculateCost(time: String, startAt: Int, moveCost: Int, pushCost: Int): Int {\n        var currentDigit = startAt\n        var result = 0\n        (0..time.lastIndex).forEach { timeCharIdx ->\n            val digit = time[timeCharIdx].digitToInt()\n            if (digit == currentDigit) {\n                result += pushCost\n            } else {\n                result += moveCost\n                result += pushCost\n                currentDigit = digit\n            }\n        }\n        return result\n    }\n\n}\n```
['Kotlin']