C++ | O(1) time and space solution
Some points to remember\n We can have atmost 99 minutes and atleast 00 minutes in minutes dial\n We can have atmost 99 seconds and atleast 00 seconds in seconds
**Some points to remember**\n* We can have atmost 99 minutes and atleast 00 minutes in minutes dial\n* We can have atmost 99 seconds and atleast 00 seconds in seconds dial \n\nLet **mins = targetSeconds/60** and **secs = targetSeconds%60**, then we just need to check for minutes={mins-1, min}. This can easily be understood with the following example,\n\n**Example** : *startAt = 1, moveCost = 2, pushCost = 1, targetSeconds = 600*\nHere, mins = 6000/60 = 100 and secs = 6000%60 = 0\nmins = 100, which cannot be entered into the minutes dial, so we decrease value of *mins* and add 60 to *secs*.\nThen, min=99, secs=60, and after calculation, we get cost=10. Again, decreasing the value of *mins* and increasing *secs*, \nwe get min=98, secs=120. But, *secs=120* is not valid.\nThis way the previous values of minutes and seconds will not be valid inputs, so we stop here.\n\nI hope the approach is clear, if you have any doubts then feel free to ask in the comments.\n**Plz upvote if you liked it!!**\n\n```\nclass Solution {\npublic:\n    int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n        int mins = targetSeconds/60;\n        int secs = targetSeconds%60;\n        \n\t\twhile(mins>99) {    // to ensure that \'minutes\' remain smaller than 100 and accordingly adding \'seconds\'\n            mins--;\n            secs += 60;\n        }\n        \n        int ans = INT_MAX;\n        while(mins>=0 and secs<100) {    // as \'minutes\' are decreasing and \'seconds\' are increasing\n            string s = (mins == 0 ? "" : to_string(mins));\n            if(mins > 0) {\n                if(secs == 0)\n                    s += "00";\n                else if(secs < 10)\n                    s += "0" + to_string(secs);\n                else\n                    s += to_string(secs);\n            }\n            else    // when \'minutes\'=0, then we just need to enter the digits of \'seconds\' in microwave dial\n                s += (secs==0 ? "" : to_string(secs));\n\n            int t=0;\n\t\t\tchar previousCharacter = startAt+\'0\';\n            for(auto i: s) {\n                if(previousCharacter == i)    // no need to move from current character, just press the key\n                    t += pushCost;\n                else\n                    t += moveCost + pushCost;\n\t\t\t\tpreviousCharacter = i;\n            }\n            ans = min(ans, t);\n            mins--;\n            secs += 60;\n        }\n        return ans;\n    }\n};\n```
[]