javascript dfs/backtracking build clock string 792ms
\nlet start, mc, pc, res, sec;\nconst minCostSetTime = (startAt, moveCost, pushCost, targetSeconds) => {\n    start = startAt, mc = moveCost, pc = pushCost, res
```\nlet start, mc, pc, res, sec;\nconst minCostSetTime = (startAt, moveCost, pushCost, targetSeconds) => {\n    start = startAt, mc = moveCost, pc = pushCost, res = Number.MAX_SAFE_INTEGER, sec = targetSeconds;\n    dfs(0, \'\');\n    return res;\n};\n\nconst dfs = (idx, cur) => {\n    if (cur.length > 4) return;\n    if (cur.length == 1 || cur.length == 2) { // length is 1 or 2, only can be minutes  like "76", "9"\n        if (cur - \'0\' == sec) res = Math.min(res, cal(cur))\n    }\n    if (cur.length == 4 || cur.length == 3) { // length is 3 or 4, calculate hours and seconds\n        let h, m;\n        if (cur.length == 3) {\n            h = cur.slice(0, 1) - \'0\';\n            m = cur.slice(1) - \'0\';\n        } else {\n            h = cur.slice(0, 2) - \'0\';\n            m = cur.slice(2) - \'0\';\n        }\n        if (h * 60 + m == sec) res = Math.min(res, cal(cur))\n    }\n    for (let i = 0; i < 10; i++) { // build clock string\n        cur += i + \'\';\n        dfs(i, cur);\n        cur = cur.slice(0, -1);\n    }\n};\n\nconst cal = (s) => { // calculate built clock string seconds\n    let sum = 0, pre = start;\n    for (const c of s) {\n        if (c - \'0\' != pre) {\n            sum += mc;\n        }\n        sum += pc;\n        pre = c - \'0\';\n    }\n    return sum;\n};\n```
['Backtracking', 'Depth-First Search', 'JavaScript']