Minimum Cost to Set Timer at Target Time
Intuition\nThe problem appears to involve determining the minimum cost required to set a timer to reach a target time, considering the cost of moving the timer\
# Intuition\nThe problem appears to involve determining the minimum cost required to set a timer to reach a target time, considering the cost of moving the timer\'s digits and pushing the timer\'s button.\n\n# Approach\n1. Initialize a vector to store the possible representations of the target time in terms of hours and minutes.\n2. If the target time is less than 100 seconds, convert it to a string and store it directly in the vector.\n3. If the target time is greater than or equal to 100 seconds, convert it to hours and minutes. Store both representations in the vector.\n4. Calculate the minimum cost for each representation by iterating through the vector:\n   - Initialize the cost and current time.\n   - Iterate through each digit of the representation:\n     - If the digit is different from the current digit of the timer, add the move cost and update the current time.\n     - Add the push cost for pressing the timer button.\n   - Update the minimum cost found so far.\n5. Return the minimum cost.\n\n# Complexity\n- Time complexity: O(n), where n is the number of representations of the target time in the vector. Each representation requires iterating through its digits.\n- Space complexity: O(n), where n is the number of representations of the target time stored in the vector.\n# Code\n``` C++ []\nclass Solution {\npublic:\n    int minCostSetTime(int startAt, int moveCost, int pushCost, int target) {\n        vector<string> v;\n        if(target < 100){\n            v.push_back(to_string(target));\n            int m = target / 60, sc = target % 60;\n            string ssc = "";\n            if(sc < 10){\n                ssc += \'0\';\n                ssc += to_string(sc);\n            }else{\n                ssc = to_string(sc);\n            }\n            v.push_back(to_string(m)+ssc);\n        }else{\n            int m = target / 60, sc = target % 60;\n            if(m < 100){\n                string ssc = "";\n                if(sc < 10){\n                    ssc += \'0\';\n                    ssc += to_string(sc);\n                }else{\n                    ssc = to_string(sc);\n                }\n                v.push_back(to_string(m)+ssc);\n            }\n            if(60 + sc < 100){\n                v.push_back(to_string(m-1)+ to_string(sc+60));\n            }\n        }\n        int res = INT_MAX;\n        for(int i=0; i<v.size(); i++){\n            int cost = 0, cur = startAt;\n            for(int j=0; j<v[i].size(); j++){\n                if(v[i][j]-\'0\' != cur){\n                    cost += moveCost;\n                    cur = v[i][j]-\'0\';\n                }\n                cost += pushCost;\n            }\n            res = min(res, cost);\n        }\n        return res;\n    }\n};\n```\n```javascript []\nfunction minCostSetTime(startAt, moveCost, pushCost, target) {\n    let v = [];\n    if (target < 100) {\n        v.push(target.toString());\n        let m = Math.floor(target / 60);\n        let sc = target % 60;\n        let ssc = "";\n        if (sc < 10) {\n            ssc += \'0\';\n            ssc += sc.toString();\n        } else {\n            ssc = sc.toString();\n        }\n        v.push(m.toString() + ssc);\n    } else {\n        let m = Math.floor(target / 60);\n        let sc = target % 60;\n        if (m < 100) {\n            let ssc = "";\n            if (sc < 10) {\n                ssc += \'0\';\n                ssc += sc.toString();\n            } else {\n                ssc = sc.toString();\n            }\n            v.push(m.toString() + ssc);\n        }\n        if (60 + sc < 100) {\n            v.push((m - 1).toString() + (sc + 60).toString());\n        }\n    }\n    let res = Number.MAX_SAFE_INTEGER;\n    for (let i = 0; i < v.length; i++) {\n        let cost = 0;\n        let cur = startAt;\n        for (let j = 0; j < v[i].length; j++) {\n            if (parseInt(v[i][j]) !== cur) {\n                cost += moveCost;\n                cur = parseInt(v[i][j]);\n            }\n            cost += pushCost;\n        }\n        res = Math.min(res, cost);\n    }\n    return res;\n}\n\n```\n]\n
['Math', 'Enumeration', 'C++', 'JavaScript']