Simple function-based solution
Intuition\nmin = targetSeconds/60;\nsec = targetSeconds%60;\nThere can be only 2 possible ways\neither answer will be min60 + sec = target\nor (min-1)60 + sec +
# Intuition\nmin = targetSeconds/60;\nsec = targetSeconds%60;\nThere can be only 2 possible ways\neither answer will be min*60 + sec = target\nor (min-1)*60 + sec + 60 = target\n\n\n# Complexity\n- Time complexity: $$O(n)$$\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```\nclass Solution {\npublic:\n    // To find correct time format of 4 digit\n    // int min, int sec => mmss format\n    string toTime(int t) {\n        string timeStr = "";\n        if(t < 10) {\n            timeStr += \'0\';\n            timeStr += to_string(t);\n        } else {\n            timeStr = to_string(t/10) + to_string(t%10);\n        }\n        return timeStr;\n    }\n\n    int cost(int m, int s, int startAt, int moveCost, int pushCost) {\n        int cost = 0, i = 0;\n        string time = toTime(m) + toTime(s);\n        // Avoiding leading zeros as we don\'t need to push it\n        while(time[i] == \'0\' && i < 4)i++;\n        for(; i < time.size(); i++){\n            int digit = time[i] - \'0\';\n            if(digit != startAt) {\n                startAt = digit;\n                cost += (moveCost + pushCost);\n            } else {\n                cost += pushCost;\n            }\n        }\n        return cost;\n    }\n    int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n        int m = targetSeconds/60;\n        int s = targetSeconds%60;\n        int minCost = INT_MAX;\n        // There can be only 2 possible ways\n        // either answer will be m*60 + sec = target\n        // or (m-1)*60 + sec + 60 = target\n        if(m <= 99)\n            minCost = cost(m, s, startAt, moveCost, pushCost);\n        if(s + 60 < 100) {\n            minCost = min(minCost, cost(m-1, s + 60, startAt, moveCost, pushCost));\n        }\n        return minCost;\n    }\n};\n```
['C++']