Implementation
Intuition10:00 <=> 09:60
mm:ss <=> mm-1:ss+60Try two cases for given targetSeconds.ApproachCosts:
moveCost : cost for changing number
pushCost: cost for fixing
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

10:00 <=> 09:60
mm:ss <=> mm-1:ss+60

Try two cases for given targetSeconds.

# Approach
<!-- Describe your approach to solving the problem. -->

Costs:
- moveCost : cost for changing number
- pushCost: cost for fixing number

Initial Conditions:
- startAt : previous digit
- targetSeconds : generate two targets (mm:ss, mm-1:ss+60)

1. transform targetSeconds to unit of minute and second
   mm = targetSeconds / 60, ss = targetSeconds % 60
2. generate second target : if mm > 0 and ss < 40, then mm-1:ss+60
3. call a helper function that calculates cost of generated (mm:ss) targets.
   - set prev_digit = startAt
   - for every digits in `mm*100 + ss`, 
       if (prev_digit != curr_digit) addup moveCost
			 addup pushCost
	 - return sum of costs
4. return mimimum sum of costs.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(1)$$
takes const time for every calculation.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
$$O(1)$$
no additional heap spaces.

# Code
```cpp []
class Solution {
public:
    int minCostSetTime(int startAt, int moveCost, int pushCost,
                       int targetSeconds) {
        auto cost = [&](char prev_num, int m, int s) {
            if (m < 0 || m > 99) return INT_MAX;
            if (s < 0 || s > 99) return INT_MAX;

            int res = 0;
            for (char num : to_string(m * 100 + s)) {
                res += (pushCost + (prev_num == num ? 0 : moveCost));
                prev_num = num;
            }
            return res;
        };

        int m = targetSeconds / 60, s = targetSeconds % 60;
        return min(cost(startAt + '0', m, s),
                   cost(startAt + '0', m - 1, s + 60));
    }
};
```
['C++']